Skip to content

Commit 4f2e7a9

Browse files
committed
fix queue in LanScanner an PortScanner
1 parent 9d77106 commit 4f2e7a9

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

hacklib.py

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -118,17 +118,25 @@ def __init__(self, IP, port=21):
118118
self.username = ''
119119
self.password = ''
120120
self.s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
121-
self.s.settimeout(3)
121+
self.s.settimeout(5)
122122
self.s.connect((self.IP, self.port))
123123
self.s.recv(1024)
124124

125-
def send(self, message):
125+
def _send(self, message):
126126
self.s.send(message)
127-
return self.s.recv(2048)
127+
response = self.s.recv(32768)
128+
return response
129+
130+
def send(self, message):
131+
self.s.send(message + '\r\n')
132+
while True:
133+
response = self.s.recv(32768)
134+
if response:
135+
return response
128136

129137
def login(self, username, password):
130-
self.send('USER ' + username + '\r\n')
131-
response = self.send('PASS ' + password + '\r\n')
138+
self._send('USER ' + username + '\r\n')
139+
response = self._send('PASS ' + password + '\r\n')
132140
if '230' in response:
133141
return
134142
elif '331' in response:
@@ -269,7 +277,7 @@ def launch(self, host, duration, threads = 1, port = 80, payload = 'default'):
269277
self.time_length = duration
270278
if payload != 'default': self.payload = payload
271279
# Creates queue to hold each thread
272-
self.q = Queue()
280+
self.q = Queue.Queue()
273281
#print '> Launching ' + str(threads) + ' threads for ' + str(duration) + ' seconds.'
274282
for i in range(threads):
275283
t = threading.Thread(target=self._threader)
@@ -352,7 +360,7 @@ def scan(self, IP, port_range = (1, 1025), timeout = 1, verbose = True):
352360
self.port_range = port_range
353361
self.timeout = 1
354362
# Creates queue to hold each thread
355-
self.q = Queue()
363+
self.q = Queue.Queue()
356364
for x in range(30):
357365
t = threading.Thread(target=self._threader)
358366
t.daemon = True
@@ -403,7 +411,7 @@ def scan(self, h_range = (1, 255)):
403411
# Adds list of possible local hosts to self.range_range
404412
for i in range(h_range[0], h_range[1]):
405413
self.host_range.append(stub + '.' + str(i))
406-
self.q = Queue()
414+
self.q = Queue.Queue()
407415
# Launches 100 threads to ping 254 potential hosts
408416
for x in range(100):
409417
t = threading.Thread(target=self._threader)
@@ -521,6 +529,10 @@ def importFromString(code, name):
521529
def getIP(host):
522530
return socket.gethostbyname(host)
523531

532+
def randomIP():
533+
import struct
534+
return socket.inet_ntoa(struct.pack('>I', random.randint(1, 0xffffffff)))
535+
524536
def getProxies(country_filter = 'ALL', proxy_type = ('Socks4', 'Socks5')):
525537
'''Gets list of recently tested Socks4/5 proxies.
526538
Return format is as follows:

0 commit comments

Comments
 (0)