Untitled
unknown
plain_text
3 years ago
2.1 kB
7
Indexable
import os
from pwn import *
import shutil
#######Modificare i vostri dati#########################################
# per vedere il nome utente eseguire:
# $cd -> $pwd -> /home/userName
userName = "ivan" #inserire il proprio nomeUtenteKali
ipServer = "10.60.4.1" #inserire l'ip del server
userServer = "root" #inserire nome del utente Server(in genere "root")
########################################################################
################DO#NOT#TOUCH############################################
#cartella .ssh in /home/username/
sshDir = "/home/"+userName+"/.ssh"
keysName = "prova"
sshKeysPath = sshDir+"/sshKeys"
SKPath = sshKeysPath+"/"+keysName
PKPath = sshKeysPath+"/"+keysName+".pub"
#make dir .ssh in /home/username/
try:
os.mkdir(sshDir)
except:
os.system("rm -rf "+sshDir)
os.mkdir(sshDir)
os.mkdir(sshKeysPath)
os.system("rm ./"+keysName+"*")
os.system('ssh-keygen -b 4096 -f '+ keysName +' -q -N ""')
shutil.copyfile(keysName,SKPath)
shutil.copyfile(keysName+".pub",PKPath)
os.chmod( SKPath,stat.S_IRWXU)
#Config file creation
f = open(sshDir+"/config","w")
f.write("Host "+ipServer+"\n")
f.write("Hostname "+ipServer+"\n")
f.write("User "+userServer +"\n")
#f.write("Port 2022\n")#Only for ivan server
f.write("PubKeyAuthentication yes\n")
f.write("IdentitiesOnly yes\n")
f.write("IdentityFile "+SKPath+"\n")
f.close()
########################################################################
print("EXECUTE THE COMMAND:\nssh-copy-id -i "+PKPath+" "+userServer+"@"+ipServer)
print("NEED to change something in the server")
print("TO CONNECT WITH THE SERVER USE:\nssh "+ipServer)
#now it is possible to connect with the server with
#ssh X.X.X.X
#without the use of the password and username
'''
********************************
cambiare password
$passwd
********************************
$sudo vim /etc/ssh/sshd_config
PubkeyAuthentication yes
'esc'+ ":wq"
********************************
$sudo service ssh restart
********************************
'''Editor is loading...