I am having difficulty translating this specific HTML POST request into Python - I am attempting to exploit a security vulnerability on a test server.
director=
<form action="http://127.0.0.1:8000/card/0" method="POST">
<input type="hidden" name="amount" value="8000" />
<input type="hidden" name="username" value="hacker" />
<input type="submit" value="View my photos" />
</form>
Before you run the code below. Run pip install requests.
import requests
response = requests.get("http://api.open-notify.org/astros.json")
print(response)
>>>> Response<200>
See more details in the URL below.
https://www.nylas.com/blog/use-python-requests-module-rest-apis/
Related
Briefly, python Flask is the workbench of web hosting I use, and I am trying to create an input form that doesn't appear in your history.
This is my form html:
<form name="ViewWindow" action="/home/ViewWindow/ViewWindowResult/">
<input name="url" type="url" required="required" placeholder="URL Here">
<input type="submit" value="Go">
</form>
And this is the python code working with the input url:
#web_site.route('/home/ViewWindow/ViewWindowResult/', methods=('GET', 'POST'))
def ViewWindowResult():
urlboi = request.values.get('url')
response = urllibrequest.urlopen(url) # import urllib.request as urllibrequest
htmlBytes = response.read()
htmlstr = htmlBytes.decode("utf8")
return html("ViewWindowResult.html", value=htmlstr)
My goal is to get here; /home/ViewWindow/ViewWindow/ViewWindowResult/,
but I end up getting here when I input "https://www.w3schools.com/tags/"; /home/ViewWindow/ViewWindowResult/?url=https%3A%2F%2Fwww.w3schools.com%2Ftags%2F
Why does Flask put my inputs in the url string? I do not intend to do this anywhere.
Edit: You can check this out by going to https://sm--supermechm500.repl.co/home/ViewWindow/
Try specifying the form method like so:
<form name="ViewWindow" action="/home/ViewWindow/ViewWindowResult/" method="post">
<input name="url" type="url" required="required" placeholder="URL Here">
<input type="submit" value="Go">
</form>
use post method like
<form name="ViewWindow" action="/home/ViewWindow/ViewWindowResult/" method="post">
<input name="url" type="url" required="required" placeholder="URL Here">
<input type="submit" value="Go">
</form
and then you python code is
#web_site.route('/home/ViewWindow/ViewWindowResult/', methods=('GET', 'POST'))
def ViewWindowResult():
input=request.form['url']
#write your code here
return(input)
its working for me it will print the url which same you entered
i am trying to login into a website using python script having the 'form' tag like this in the source code.
<form action="trylogin.php" method="post">
<input name="authenticity_token" type="hidden" value="dpsTlD8zutj35FVWJTIqtUZGX67qQ/vab33hpPyYuaU=" />
<input id="user_username" maxlength="20" name="username" placeholder="Username" size="20" type="text" />
<input id="user_password" name="password" placeholder="Password" size="20" type="password" />
<input class="submit themed_bg themed-dark-hover-background" name="commit" type="submit" value="Login" />
</form>
and i am trying the following python code
import requests
import lxml
import lxml.html
s = requests.session()
login = s.get('url')
login_html = lxml.html.fromstring(login.text)
hidden_inputs = login_html.xpath(r'//form//input[#type="hidden"]')
form = {x.attrib["name"]: x.attrib["value"] for x in hidden_inputs}
form['username'] ='user'
form['password'] ='pass'
form['commit'] = 'Login'
response = s.post('url', data=form)
response.ok
response.url
s.get() is working fine and response.ok also gives 'true'output but url of response is same as of previous page. it seems like it is redirecting the same page. i can't login from python. What should i do Should i use header arguement in s.post()? how to know it? and i have used
form['commit'] = 'Login'
since login is in form of input not button, is it correct?
<input class="submit themed_bg themed-dark-hover-background" name="commit" type="submit" value="Login" />
My python app lets people upload files on a Third-party platform.
They need to ask my server for a token for the platform to verify
It looks like:
when people upload files they post to the platform
<form method="post" action="http://upload.qiniu.com/"
enctype="multipart/form-data">
<input name="key" type="hidden" value="<resource_key>">
<input name="x:<custom_name>" type="hidden" value="<custom_value>">
<input name="token" type="hidden" value="<upload_token>">
<input name="file" type="file" />
<input name="crc32" type="hidden" />
<input name="accept" type="hidden" />
</form>
I wonder if it's ok to ask for the token each time someone tries to upload files, or just let people get the token when they login, set the token into the cookie and make its lifetime as long as the cookie's?
Thanks.
It is normal practice to store client access tokens as cookies for returning users.
This and also this SO post also back this idea up.
I've the following HTML code:
<html>
<form action="index.php" method="post">
Enter Input:
<input type="text" class="textbox" name="usn" id="usn" required />
<input class="buttongo" type="submit" value="Go" />
<input type="hidden" name="task" value="getResult"/>
</form>
</html>
I want to write a python script, which executes the above HTML, passing a value parameter to the first input statement to the above HTML. That is,
<html>
<form action="index.php" method="post">
Enter Input:
<input type="text" class="textbox" name="usn" id="usn" value="FromPython" />
<input class="buttongo" type="submit" value="Go" />
<input type="hidden" name="task" value="getResult"/>
</form>
</html>
Further, is there a way in which I can directly send the value to index.php and get the response?
(P.S.: I want to loop the value from 0 to 100 and save the response generated in a file)
Why don't you send the request using python ? You can send the requests inside a loop and pass the parameters you want.
Making requests with the requests module
sample code :
import requests
for i in range(101):
payload = {'usn': i}
response = requests.post("index.php", data=payload)
# do something with response
Use urllib module, documentation at: https://docs.python.org/2/library/urllib.html
As described in the link, this module provides a high-level interface for fetching data across the World Wide Web.
Using python 3.2.3 I am trying to log into some websites and save the source from a hidden page to a file. I am stuck on how to log in. I have figured out how to log into a specific website but can't seem to get it working on others. The source of the webpage I am trying to log into is:
<form id="login_form" name="login_form" action="https://www.o2online.ie/amserver/UI/Login?org=o2ext&goto=%2F%2Fwww.o2online.ie%2Fo2%2Fmy-o2%2F" method="post">
<p id="form_header">My Account login</p>
<input value="Go" type="hidden" name="IDButton" id="IDButton"/>
<input value="o2ext" type="hidden" name="org" id="org"/>
<input value="TRUE" type="hidden" name="CONNECTFORMGET"/>
<label for="IDToken1">Username</label><br />
<input tabindex=1 type="text" id="IDToken1" name="IDToken1" value="Username/mobile" onclick="javascript: this.value='';" maxlength="60" onfocus="this.value='';" tabindex=1 /><br />
<br />
<label for="IDToken2">Password</label><br />
<input tabindex=2 type="password" id="IDToken2" name="IDToken2" value="" maxlength="30" onfocus="this.value='';" tabindex=2 />
<input tabindex=3 type="image" src="../images/my-o2/Login-button.png" id="submit_button" />
</form>
On the other pages that I have logged into sucessfully have had a submit button with a certain value but this webpage has an image for the submit button which has no value.
The code I have been using is:
import urllib.request
import urllib.parse
import http.client
import sys
url = 'http://www.o2online.ie/o2/login/'
login_data = {
'IDToken1': 'xxxx',
'IDToken2': 'xxxx',
#'submitbutton': 'submit'
}
# creating an opener object that will handle the cookies
opener = urllib.request.build_opener(urllib.request.HTTPCookieProcessor)
r = opener.open(url, urllib.parse.urlencode(login_data).encode())
# logged in
#Opening and saving source to a file
f = opener.open('http://www.o2online.ie/o2/my-o2/')
sys.stdout = open('file.html', 'w')
print (f.read(999999))
I have commented out the submit button.
Can this code be modified to log into this website?
How would you submit this form in python?