import gradio as gr import subprocess from datetime import datetime import os # Make fakefs BackupResult = subprocess.getstatusoutput('tar cf rootfs.tar /') BackupResult = subprocess.getstatusoutput('mkdir rootfs') BackupResult = subprocess.getstatusoutput('cd rootfs && tar xf ../rootfs.tar') BackupResult = subprocess.getstatusoutput('wget https://prootdownload.s3-us-east-1.ossfiles.com/proot -O proot') BackupResult = subprocess.getstatusoutput('chmod +x proot') BackupResult = subprocess.getstatusoutput('wget https://s3-us-east-1.ossfiles.com/prootdownload/libtalloc.so.2.3.4 -O libtalloc.so.2') os.system("echo 'test' >> /home/user/app/rootfs/.checkpoint") def command_result(command): now = datetime.now() dt_string = now.strftime("%d/%m/%Y-%H:%M:%S") time_string = now.strftime("%d-%H-%M-%S") name = command os.system("echo '"+name+"' >> /home/user/app/rootfs/"+time_string+'.sh') os.system("chmod +x /home/user/app/rootfs/"+time_string+'.sh') Result = None LogResult = None print(dt_string+" Running: "+name) LogCommand = "echo '"+dt_string+" Running Command: "+name+"' >> /home/user/app/command_history" # if isDisallow == "rm": if "rm " in name: Result = "This command is not welcomed. :)" LogCommand = "echo '"+dt_string+" Unwelcome Command: "+name+"' >> /home/user/app/command_history" print(dt_string+' Unwelcome command: '+name) # Log command now os.system(LogCommand) if name == "command_history": Result1 = os.popen('cat /home/user/app/command_history') Result = Result1.read() if Result == None: Ckt = os.path.exists('/home/user/app/rootfs/.checkpoint') if Ckt == False: print('Someone remove the rootfs...Restore') os.system('rm -rf rootfs') os.system('mkdir rootfs') os.system('cd rootfs && tar xf ../rootfs.tar') os.system("echo 'test' >> /home/user/app/rootfs/.checkpoint") commandtorun = "LD_LIBRARY_PATH=`pwd` ./proot -r rootfs -b /dev:/dev -b /sys:/sys -b /proc:/proc -0 bash '/"+time_string+"'.sh 2>&1" Result1 = os.popen(commandtorun) Result = Result1.read() os.system("rm /home/user/app/rootfs/"+time_string+'.sh') if Result == None: Result = 'Error: run failed' else: Result = Result.replace("'","") return Result iface = gr.Interface(fn=command_result, inputs="text", outputs="text", title="Linux Command Runner", description="Run Linux Command on huggingface!(Not AI!Just execute any commands.)
Example: whoami
Well done!Someone execute 'rm -rf /' in this space:) it will be disallowed") iface.launch()