2 Replies - 1181 Views - Last Post: 12 February 2015 - 08:12 PM Rate Topic: -----

#1 Hrand   User is offline

  • D.I.C Head

Reputation: 7
  • View blog
  • Posts: 109
  • Joined: 25-June 12

Submit post data on forms html

Posted 11 February 2015 - 11:47 PM

Okay, so I've gotten most of the code to work. I'm have problems submitting my data via html forms and post. Here is the link to the problem i'm working on, thought you'll need an account to view it. https://www.hackthis...ssions/prog/11/

Here is my python code

import urllib, urllib2, cookielib

host = 'www.hackthissite.org'
user_agent = 'Mozilla/4.0 (compatible; MSIE 6.0)'
referer = 'http://www.hackthissite.org/user/login'
content_type = 'application/x-www-form-urlencoded'
accept_encoding = 'gzip,deflate'

body = {'username': 'XXXXXXXXX', 'password': 'XXXXXXXXX'}


values = {'Host': 'www.hackthissite.org',
          'User-Agent':'Mozilla/4.0 (compatible; MSIE 8.0)',
          'Referer':'http://www.hackthissite.org/user/login',
          'Content-Type':'application/x-www-form-urlencoded',
          'Accept-Encoding':'gzip,deflate',
          }

#build cookie handler
cj = cookielib.CookieJar()
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
urllib2.install_opener(opener)

#encode request information
data = urllib.urlencode(body)

#send login information
req = urllib2.Request(referer, data, values)
page = urllib2.urlopen(req)


#start opening pages
url = "http://www.hackthissite.org/missions/prog/11/"


page2 = urllib2.urlopen(url)
html_content = str(page2.read())
#html_content = page2.read()
#html_content = html_content.decode("ISO-8859-1")


def find_key():
    key = html_content.find("Shift:")
    html_content_key = html_content[key+6:key+9]

    return int(str(html_content_key).replace('>',"").replace(" ","").replace('<', ""))


def tsplit(s, sep):
    stack = [s]
    for char in sep:
        pieces = []
        for substr in stack:
            pieces.extend(substr.split(char))
        stack = pieces
    return stack


def find_encrypted_string():
    split_string = []
    start_of_string = html_content.find("String:")
    end_of_string = html_content.find("Shift:")
    encrypted_string = html_content[start_of_string+8:end_of_string-12]
    encrypted_string = tsplit(encrypted_string, "!@#$%^&*()_+-={}[]\|;'\":<>?,./")
    encrypted_string = filter(None, encrypted_string)
    encrypted_string = [int(i) for i in encrypted_string]
    return encrypted_string
        
def getCypheredText(inputWord,shift):
    shiftedInputWordList=[chr(int(x)-int(shift)) for x in inputWord]
    return ''.join(shiftedInputWordList)
    

key_shift = find_key()
encrypted_string =  find_encrypted_string()
cyphered_text = getCypheredText(encrypted_string, key_shift)

"""THIS IS WHERE I AM HAVING TROUBLE.  I WANT TO SEND MY ANSWER TO THE SITE AND VIEW THE HTML OF THE PAGE AFTER SUBMITTING THE ANSWER """
form_data = {'submit' : cyphered_text}
encoded_data = urllib.urlencode(form_data) 
f = urllib.urlopen(url, encoded_data) 
result = f.read() 
print result
f.close() 




Also, just incase it is is needed here is the html code for the page i'm working with.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>
  <title>Hack This Site!</title>
  <meta name="verify-v1" content="s/YXn7eQrMBoF9PL5jLJDiWpAxEXpJzE9JLg/zM4C2Y=" />
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <meta name="Author" content="HackThisSite.org Crew." />
  <meta name="Description" content="HackThisSite! is a legal and safe network security resource where users test their hacking skills on various challenges and learn about hacking and network security. Also provided are articles, comprehensive and active forums, and guides and tutorials. Learn how to hack!" />
  <meta name="KeyWords" content="challenge, computer, culture, deface, digital, ethics, games, guide, hack, hack forums, hacker, hackers, hacking, hacking challenges, hacking forums, mission, net, programming, radical, revolution, root, rooting, security, site, society, tutorial, tutorials, war, wargame, wargames, web, website" />
    <link rel="icon" href="https://data.htscdn.org/favicon.ico" type="image/x-icon" />
  <link rel="shortcut icon" href="https://data.htscdn.org/favicon.ico" type="image/x-icon" />
  <link href="https://data.htscdn.org/themes/Dark/Dark.css" rel="stylesheet" type="text/css" />
  <link href="https://www.hackthissite.org/pages/hts.rss.php" rel="alternate" type="application/rss+xml" title="HTS RSS feed" />
  <base href="https://www.hackthissite.org" />
  <script type="text/javascript" src="https://data.htscdn.org/js/jquery-1.8.1.min.js"></script>
<script type="text/javascript">
(function() {
  function async_load(script_url){
    var protocol = ('https:' == document.location.protocol ? 'https://' : 'http://');
    var s = document.createElement('script'); s.src = protocol + script_url;
    var x = document.getElementsByTagName('script')[0]; x.parentNode.insertBefore(s, x);
  }
  bm_website_code = '3CBA71AF7B7E4145';
  jQuery(document).ready(function(){async_load('asset.pagefair.com/measure.min.js')});
  jQuery(document).ready(function(){async_load('asset.pagefair.net/ads.min.js')});
})();
</script>
  </head>
<body>
<span id="blank-element" style="display: none"></span>

<div id="topbar" align="center">
<a href="https://www.hackthissite.org" id="active">HackThisSite</a> - <a href="irc://irc.hackthissite.org:+7000/">IRC</a> - <a href="https://www.hackthissite.org/forums">Forums</a> - <a href="http://radio.hackthissite.org">Radio</a> - <a href="http://hts.io/x/http://www.cafepress.com/htsstore" target="_new">Store</a> - <a href="http://hts.io" target="_new">URL Shortener</a>&nbsp;&nbsp;&nbsp;---&nbsp;&nbsp;&nbsp;<a href="http://hts.io/x/https://www.facebook.com/hackthissite" target="_new">Like Us</a> - <a href="http://hts.io/x/https://twitter.com/#!/hackthissite" target="_new">Follow Us</a></div>
<div class="hts-header">
<a href="/"><img src="https://data.htscdn.org/themes/Dark/images/header.jpg" alt="Hack This Site" border="0" /></a>
<br />
<a href="https://www.hackthissite.org/Jim8H3ShA78CY4Wj46RET3xsPAyPpQHa1OfQ1BbOK5x7auIQSP6M1KFao400Nc5927cefZBACY23dACS8zxaZQS4dXn7v" target="_blank"><img src="https://www.hackthissite.org/hi10Bl1A471649Gc3riPt2xAjTUQ1la5p4W3vS9Pv40tqQC9Nt493OX0bmg6FZk6CmVZ5Btur5o3qR46c602qoJSyt2nKM9E1oG8zRguSZv1z0mnKdTcyZF7F00qgAwuFp4Awr1NhMu92yzYo8W3M2yvEz01asp4OXH0R04174iSLF4P2" alt="Scan Your Website with Netsparker Web Security Scanner" id="atimg" class="abstaimg" title="Scan Your Website with Netsparker Web Security Scanner" border="0" /></a><br />[<a href="https://www.hackthissite.org/advertise/">Advertise With HackThisSite.org</a>]</div>
  <table width="780" border="0" cellpadding="0" cellspacing="0" class="siteheader cmTable">
    <tr>
      <td class="sitetopheader"><blockquote>"Every system, no matter how secure and well-designed, will be broken by some idiot user." -James Gaskin</blockquote></td>
    </tr>
    <tr>
      <td><table width="100%"  border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td width="160" valign="top" class="navbar"><div align="center">
            <br />
            <div style="margin-right: 7px; border: 3px double #555555; background-color: #006600; font-weight: bold">
<img src="https://data.htscdn.org/images/lock.png" style="float: left; margin: 4px 0 0 5px">
You are browsing HackThisSite over SSL
</div>
<br />	<div>Hello, <a href="/user/view/pythonpentester115/">pythonpentester115</a><br />
		<a href="/user/edit/2025540/">Settings</a> - <a href="/?logout&nce=N9Mu390nGFjqeKEnY1l653pXnwSvDFJ2UOTL7YAWP">Logout</a><br /><br />
		<a class="nav" href="/user/themes/"> Skin Chooser</a><br /><br />
	<a class="nav" href="http://www.hackthissite.org/forums/ucp.php?i=pm">Private Messages</a><br />
	<a class="nav" href="/pages/messages/msys/">HTS Messages Center</a><br />
	You have 0 new messages.<br />
	</div>

	<h4 class="header">Donate</h4>
<p>
  <a href="https://www.hackthissite.org/donate/">
    <img
      src="https://data.htscdn.org/images/donate.png"
      border="0"
      title="Donate to HackThisSite.org"
      alt="Donate to HackThisSite.org" />
  </a>
  <br />
  HTS costs up to $300 a month to operate. We <strong>need</strong> your help!
</p>
<h4 class="header">Challenges</h4>
<ul class="navigation">
  <li><a class="nav" href="/missions/basic/">Basic missions</a></li><li><a class="nav" href="/missions/realistic/">Realistic missions</a></li><li><a class="nav" href="/missions/application/">Application missions</a></li><li><a class="nav" href="/missions/programming/">Programming missions</a></li><li><a class="nav" href="/missions/phonephreaking/">Phonephreaking missions</a></li><li><a class="nav" href="/missions/javascript/">Javascript missions</a></li><li><a class="nav" href="/missions/forensic/">Forensic missions</a></li><li><a class="nav" href="/missions/playit/extbasic/0/">Extbasic missions</a></li><li><a class="nav" href="/missions/playit/stego/0/">Stego missions</a></li><li><a class="nav" href="irc://irc.hackthissite.org/htb">Irc missions</a></li></ul>

<h4 class="header">Get Informed</h4><ul class="navigation"><li><a class="nav" href="/blogs">Blogs</a></li><li><a class="nav" href="/news">News</a></li><li><a class="nav" href="/pages/articles/article.php">Articles</a></li><li><a class="nav" href="/lectures">Lectures</a></li><li><a class="nav" href="/pages/programs/programs.php">Useful Stuff</a></li><!--<li><a class="nav" href="ebooks">E-books</a></li>--><li><a class="nav" href="http://mirror.hackthissite.org/hackthiszine/">HackThisZine</a></li><li><a class="nav" href=""></a></li></ul><h4 class="header">Get Involved</h4><ul class="navigation"><li><a class="nav" href="/donate"><span class="completed">Donate to HackThisSite!</span></a></li><li><a class="nav" href="http://www.cafepress.com/htsstore">Store</a></li><li><a class="nav" href="/submit/article">Submit Article</a></li><li><a class="nav" href="/pages/bugManagement/index.php">Submit Bug Report</a></li><li><a class="nav" href="/submit/lecture">Submit Lecture</a></li><li><a class="nav" href="/pages/programs/insert.php">Submit Useful Stuff</a></li><!--<li><a class="nav" href="/pages/showsource/loopdeloop.php">We Want You!</a></li>--><li><a class="nav" href=""></a></li></ul><h4 class="header">Communicate</h4><ul class="navigation"><li><a class="nav" href="/forums">Forums</a></li><li><a class="nav" href="https://www.hackthissite.org/forums/ucp.php?i=pm">Private Messages</a></li><li><a class="nav" href="http://www.irc.hackthissite.org/idlerpg">IRC IdleRPG</a></li><li><a class="nav" href="https://www.hackthissite.org/irc/stats.php">IRC Stats</a></li><li><a class="nav" href="http://qdb.hackthissite.org">IRC Quotes</a></li><li><a class="nav" href="/user/search">Search Users</a></li><li><a class="nav" href="/user/gallery">User Pictures</a></li><li><a class="nav" href="/user/online">Who is Online</a></li><li><a class="nav" href="/user/rankings/">Rankings</a></li><li><a class="nav" href="/pages/irc/irc.php">IRC Chat</a></li><li><a class="nav" href="/pages/irc/reference.php">IRC Command Reference</a></li><li><a class="nav" href=""></a></li></ul><h4 class="header">About HTS</h4><ul class="navigation"><li><a class="nav" href="/info/about">About the Project</a></li><li><a class="nav" href="/info/billofrights">Bill of Rights</a></li><li><a class="nav" href="/info/legal">Legal Disclaimer</a></li><li><a class="nav" href="/info/privacy">Privacy Statements</a></li><li><a class="nav" href="/pages/info/staff">Meet the Staff</a></li><li><a class="nav" href="/info/underthehood">Under the Hood</a></li><li><a class="nav" href="/advertise">Advertise with HTS</a></li><li><a class="nav" href="/ipv6">IPv6</a></li><li><a class="nav" href="/hof">Hall of Fame</a></li><li><a class="nav" href=""></a></li></ul><h4 class="header"></h4><ul class="navigation"><li><a class="nav" href=""></a></li></ul>
<br />
<a href="/">
  <img
    src="https://data.htscdn.org/images/hts_80x15.gif"
    width="80"
    height="15"
    border="0"
    alt="" />
</a>
<br />
<a class="nav" href="https://www.hackthissite.org/pages/info/linktous.php">
  Link to us!
</a>

<h4 class="header">
  Partners
</h4>
<br />
<a target="_new" href="http://hts.io/x/http://affiliates.mozilla.org/link/banner/8528">
  <img
    src="//affiliates.mozilla.org/media/uploads/banners/ac502446d8392cea778bcdaf8b3e07f8958a0216.png"
    alt="Download Firefox"
    width="88" />
</a>
<br />
<a class="nav" target="_new" href="http://hts.io/x/http://www.hackbloc.org/">
  <img src="https://data.htscdn.org/images/linkhb.gif" border="0" alt="Hackbloc" width="88" height="31" />
</a>
<br />
<a class="nav" target="_new" href="http://hts.io/x/http://www.hellboundhackers.org/">
  <img
    src="https://data.htscdn.org/images/hbhlogo.jpg"
    width="88"
    height="31"
    border="0"
    alt="Hellbound Hackers" />
</a>
<br />
<a class="nav" target="_new" href="http://hts.io/x/https://www.mavitunasecurity.com/netsparker/">
  <img
    src="https://data.htscdn.org/images/netsparker.gif"
    alt="Mavituna Security Netsparker"
    width="88"
    height="31"
    border="0" />
</a>
<br />
<a class="nav" target="_new" href="http://hts.io/x/http://www.acunetix.com/blog">
  <img
   src="https://data.htscdn.org/images/acunetixblog.gif"
   alt="Acunetix Security Blog"
   width="88"
   height="31"
   border="0" />
</a>
<br />
<a class="nav" target="_new" href="http://hts.io/x/http://www.buddyns.com">
<img
  src="https://data.htscdn.org/images/buddyns88x31.png"
  alt="BuddyNS Secondary DNS"
  width="88"
  height="31"
  border="0" />
</a>
<br />

          </td>
          <td valign="top" class="sitebuffer">
	<br />
 <script language="Javascript">
            <!--
            var TimeRemaining;
            var Timer;

            TimeRemaining = 3
            Timer = setTimeout("countdown()", 1000);

            function countdown()
            {
               TimeRemaining--;
               document.submitform.submitbutton.value = "submit            (remaining time: " + TimeRemaining + " seconds)";
               if (TimeRemaining > 0)
                  Timer = setTimeout("countdown()", 1000);
               else
               {
                  document.submitform.submitbutton.value = "- - - - - - - - - - - - - - - -   too late   - - - - - - - - - - - - - - - -";
                  alert("Sorry, it's too late  :(/>/>/>");
               }
             }
           // -->
           </script><table border="0" style="width:100%">
             <tr>
               <td style="width:20%;"></td>
               <td>&nbsp;</td>
               <td style="width:20%;"></td>
             </tr>
             <tr>
               <td></td>
               <td style="text-indent:3cm;"><b>Level 11</b></td>
               <td></td>
             </tr>
             <tr>
               <td></td>
               <td>&nbsp;</td>
               <td></td>
             </tr>
             <tr>
               <td></td>
               <td>
	This string was randomly generated. It will not be recognizable text. You have 3 seconds to take the information from the website, and apply that
	to your algorithm. <br /><br />Generated String: 106"68"80"103"74"90"104"103"71"77"79"91"<br /><br />Shift: 28<br /><br />
	<form name="submitform" action="/missions/prog/11/index.php" method="post"><br />
	Decoded ASCII
	<input size="50" name="solution"><br /><br />
	<div style="text-align:center">
	                     <input name ="submitbutton" type="submit" value="submit            (remaining time: 3 seconds)">
	                   </div>
	                 </form>
               </td>
               <td></td>
             </tr>
             <tr>
               <td></td>
               </tr>
                 </table>
</td>
        </tr>
      </table></td>
    </tr>
 <tr>
      <td class="sitebottomheader"><img src="https://data.htscdn.org/themes/Dark/images/hts_bottomheadern.jpg" alt="End Footer" width="780" height="60" /></td>
    </tr>
  </table>
  <br />
<div align="center" style="font-family:Verdana, Arial, Helvetica, sans-serif; font-size:10px; color:#CCCCCC">HackThisSite is is the collective work of the HackThisSite staff, licensed under a <a rel="license" href="http://hts.io/x/http://creativecommons.org/licenses/by-nc/3.0/" target="_new">CC BY-NC</a> license.<br />
We ask that you inform us upon sharing or distributing.<br /><br />
<sub>Page Generated: Thu, 12 Feb 2015 06:43:50 +0000<br />Web Node: www0 | Page Gen: 0.055s | DB: 15q<br />Current Code Revision: <a href="https://www.hackthissite.org/CHANGELOG">v3.2.3
 (Fri, 27 Jun 2014 20:13:10 +0000)</a></sub><br />
</div>
</div>
<div align="center">
  <p>
   <a target="_new" href="http://hts.io/x/http://creativecommons.org/licenses/by-nc/3.0/"><img src="https://data.htscdn.org/images/cc_80x15.png" width="80" height="15" border="0" alt="" /></a>
   <a target="_new" href="http://hts.io/x/http://validator.w3.org/check?uri=referer"><img src="https://data.htscdn.org/images/xhtml10.png" width="80" height="15" border="0" alt="" /></a>&nbsp;
   <a target="_new" href="http://hts.io/x/http://jigsaw.w3.org/css-validator/check/referer"><img src="https://data.htscdn.org/images/css.png" width="80" height="15" border="0" alt="" /></a> 
   <a target="_new" href="http://hts.io/x/http://www.php.net/"> <img src="https://data.htscdn.org/images/phppow.gif" width="80" height="15" border="0" alt="" /></a>
   <!--<a href="http://www.linux.com/"> <img src="../../images/linux2.gif" width="80" height="15" border="0" alt="" /></a>-->
   <a target="_new" href="http://hts.io/x/http://www.freebsd.org/"> <img src="https://data.htscdn.org/images/freebsd.png" width="80" height="15" border="0" alt="" /></a>
   <img src="https://data.htscdn.org/images/counter.php" height="14" border="0" alt="Page View Counter" />
  </p>
</div>
<!-- <a href="http://hackthissite.org/hp.php">retired</a> --><script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
var pageTracker = _gat._getTracker("UA-2391176-1");
pageTracker._initData();
pageTracker._trackPageview();
</script>
<!--[if !(lt IE 8)]><!-->
<script type="text/javascript">
  var tdwfb_config = {greeting: 'Dear HackThisSite User'};
  (function(){
    var e = document.createElement('script'); e.type='text/javascript'; e.async = true;
    e.src = document.location.protocol + '//d1agz031tafz8n.cloudfront.net/thedaywefightback.js/widget.min.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(e, s);
  })();
</script>
<!--<![endif]-->
    </body>
</html>


This post has been edited by Hrand: 11 February 2015 - 11:47 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Submit post data on forms html

#2 Hrand   User is offline

  • D.I.C Head

Reputation: 7
  • View blog
  • Posts: 109
  • Joined: 25-June 12

Re: Submit post data on forms html

Posted 12 February 2015 - 12:02 AM

update I changed the form_data dictionary to say

form_data = {'solution' : cyphered_text}



which is the input name on this html page, i'm still not getting the page
Was This Post Helpful? 0
  • +
  • -

#3 Hrand   User is offline

  • D.I.C Head

Reputation: 7
  • View blog
  • Posts: 109
  • Joined: 25-June 12

Re: Submit post data on forms html

Posted 12 February 2015 - 08:12 PM

lol nevermind I figured it out, i was forgetting to use the same cookie. Works now.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1