Results 1 to 9 of 9

Thread: [JAVA] POST problem with Zer0's Wrapper.

  1. #1

    Rambo's Avatar
    Joined
    Sep 2013
    Posts
    136
    Userbars
    1
    Thanks
    19
    Thanked
    29/25
    DL/UL
    11/7
    Mentioned
    25 times
    Time Online
    4d 3h 14m
    Avg. Time Online
    1m

    [JAVA] POST problem with Zer0's Wrapper.

    So I am trying to use Zer0s Wrapper to make a Marapets Bot.

    Zer0's wrapper code I am using:
    Code:
    import java.io.*;
    import java.net.*;
    import java.util.*;
    import java.util.zip.*;
    import java.awt.image.BufferedImage;
    import javax.imageio.ImageIO;
    
    public class Connection implements Serializable {
       static final long serialVersionUID = 1L;
       
       String domain, referer;
       Map<String,String> cookies;
       
       static String rpUseragent = "Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.8.1.14) Gecko/20080509 Firefox/2.0.0.14";
       static String rpAcceptText = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
       static String rpAcceptPng = "image/png,image/*;q=0.8,*/*;q=0.5";
       static String rpAcceptLanguage = "en-us,en;q=0.5";
       static String rpAcceptEncoding = "gzip, deflate";
       static String rpAcceptCharset = "ISO-8859-1,utf-8;q=0.7,*;q=0.7";
       static String rpKeepAlive = "300";
       static String rpConnection = "keep-alive";
       static String rpContentType = "application/x-www-form-urlencoded";
       
       public Connection( String domain, Map<String,String> cookies, String referer ) {
          this.domain = domain;
          this.cookies = cookies;
          this.referer = referer;
       }
       
       public Connection( String domain, Map<String,String> cookies ) {
          this( domain, cookies, null );
       }
       
       public Connection( String domain, String referer ) {
          this( domain, new HashMap<String,String>(), referer );
       }
       
       public Connection( String domain ) {
          this( domain, new HashMap<String,String>(), null );
       }
       
       public String get( String url ) {
          if( url.charAt( 0 ) == '/' )
             url = domain + url;
          
          try {
             HttpURLConnection conn = (HttpURLConnection)( new URL( url.replaceAll( " ", "%20" ) ).openConnection() );
             setRequestProperties( conn );
             conn.setRequestMethod( "GET" );
             referer = url;
             return read( conn );
          } catch( IOException e1 ) {
             e1.printStackTrace();
             return null;
          }
       }
       
       public String post( String url, String[][] data ) {
          if( url.charAt( 0 ) == '/' )
             url = domain + url;
          
          try {
             HttpURLConnection conn = (HttpURLConnection)( new URL( url.replaceAll( " ", "%20" ) ).openConnection() );
             setRequestProperties( conn );
             conn.setRequestMethod( "POST" );
             conn.setDoOutput( true );
             
             StringBuilder sb = new StringBuilder();
             
             for( int i = 0; i < data[0].length; i++ )
                sb.append( URLEncoder.encode( data[0][i], "UTF-8" ) ).append( '=' ).append( URLEncoder.encode( data[1][i], "UTF-8" ) ).append( '&' );
             
             conn.setRequestProperty( "Content-Type", rpContentType );
             conn.setRequestProperty( "Content-Length", Integer.toString( sb.length()-1 ) );
              try (PrintWriter out = new PrintWriter( new BufferedWriter( new OutputStreamWriter( conn.getOutputStream() ) ) )) {
                  out.write( sb.substring( 0, sb.length()-1 ) );
              }
             
             referer = url;
             return read( conn );
          } catch( IOException e1 ) {
             e1.printStackTrace();
             return null;
          }
       }
       
       public BufferedImage getImage( String url ) {
          try {
             HttpURLConnection conn = (HttpURLConnection)( new URL( ( url.charAt( 0 ) == '/' ? domain+url : url ).replaceAll( " ", "%20" ) ).openConnection() );
             setRequestProperties( conn );
             conn.setRequestMethod( "GET" );
             conn.setRequestProperty( "Accept", rpAcceptPng );
             return ImageIO.read( conn.getInputStream() );
          } catch( IOException e1 ) {
             e1.printStackTrace();
             return null;
          }
       }
       
       public boolean hasCookie( String key ) {
          return cookies.containsKey( key );
       }
       
       public String getCookieString() {
          StringBuilder sb = new StringBuilder();
          
          for( String s : cookies.keySet() )
             sb.append( s ).append( '=' ).append( cookies.get( s ) ).append( ';' );
          
          return sb.toString();
       }
       
       private void setRequestProperties( HttpURLConnection conn ) {
          conn.setInstanceFollowRedirects( false );
          conn.setRequestProperty( "User-Agent", rpUseragent );
          conn.setRequestProperty( "Accept", rpAcceptText );
          conn.setRequestProperty( "Accept-Language", rpAcceptLanguage );
          conn.setRequestProperty( "Accept-Encoding", rpAcceptEncoding );
          conn.setRequestProperty( "Accept-Charset", rpAcceptCharset );
          conn.setRequestProperty( "Keep-Alive", rpKeepAlive );
          conn.setRequestProperty( "Connection", rpConnection );
          
          if( referer != null && referer.length() != 0 )
             conn.setRequestProperty( "Referer", referer );
          
          if( cookies != null && cookies.size() != 0 )
             conn.setRequestProperty( "Cookie", getCookieString() );
       }
       
       private String read( HttpURLConnection conn ) throws IOException {
          BufferedReader in = null;
          
          if( conn.getContentEncoding() == null )
             in = new BufferedReader( new InputStreamReader( conn.getInputStream() ) );
          else
             if( conn.getContentEncoding().equalsIgnoreCase( "gzip" ) )
                in = new BufferedReader( new InputStreamReader( new GZIPInputStream( conn.getInputStream() ) ) );
             else if( conn.getContentEncoding().equalsIgnoreCase( "deflate" ) )
                in = new BufferedReader( new InputStreamReader( new InflaterInputStream( conn.getInputStream(), new Inflater( true ) ) ) );
          
          StringBuilder sb = new StringBuilder();
          String s;
          
          while( ( s = in.readLine() ) != null )
             sb.append( s ).append( '\n' );
          
          putCookies( conn.getHeaderFields().get( "Set-Cookie" ) );
          return sb.toString();
       }
       
       private void putCookies( List<String> cookieList ) {
          if( cookieList == null )
             return;
          
          int index;
          
          for( String cookie : cookieList )
             cookies.put( cookie.substring( 0, index = cookie.indexOf( '=' ) ), cookie.substring( index+1, cookie.indexOf( ';', index ) ) );
       }
    }
    To send a post request to login to mara. The marapets form is:
    Code:
    <form action='dologin.php' method='post' name='LOGIN'>
    <table width='300' cellpadding='2' cellspacing='0' border='0' style='border: 1px solid #000000;'>
    <tr>
    <td colspan='2' bgcolor='#2EE6F0'><center><font color=white><B>Enter Password</B></td>
    </tr>
      <tr>
        <td style='border-top:1px solid #000000;'><B>Password</b>:</td>
    <input type='hidden' name='id' value='5393345'>
        <td style='border-top:1px solid #000000;'><input type='password' size='20' name='password'></td>
      </tr>
      </table>		<BR>
      <center><input type='submit' name='submit' value='Login to Marapets'  /></center>
    </form>
    Here is the code I am using to try to login:
    Code:
    Connection wrapper = new Connection("http://www.marapets.com/");
    String[][] data = new String [][] {{"id", "5xxxxxxxx"}, {"password", "pxxxxxx"}};
    wrapper.post("http://www.marapets.com/dologin.php",data); //login
    What am I doing wrong? @(you need an account to see links) @(you need an account to see links) @(you need an account to see links)

    What I get when I try to login is:
    Code:
    This is the wrong password. Are you sure you have typed it correctly?
    
    Email us at [email protected] if you have lost your password.
    
    You will receive a reply within 24 hours
    Last edited by Rambo; 03-11-2014 at 06:18 PM.

  2. #2
    Saiyan Race
    j03's Avatar
    Joined
    Dec 2011
    Posts
    13,756
    Userbars
    176
    Thanks
    5,936
    Thanked
    33,184/6,625
    DL/UL
    23/36
    Mentioned
    3,871 times
    Time Online
    564d 11h 47m
    Avg. Time Online
    3h 13m
    Might have to replace any special characters if they require that. I think Neopets does.
    (you need an account to see links)
    (you need an account to see links)(you need an account to see links)

    ------------------------
    [02/24/2013] Stealth CORE is made into the first standalone Neopets auto-player.
    ------------------------


  3. #3

    Joined
    Jun 2012
    Posts
    1,699
    Thanks
    876
    Thanked
    2,881/1,142
    DL/UL
    44/1
    Mentioned
    562 times
    Time Online
    118d 6h 45m
    Avg. Time Online
    40m
    Only thing i can think of is setting the reffer url to

    (you need an account to see links)

    If that fails try adding a form value "submit" , with the data "Login+to+Marapets" , thats all i can think of looking at ur code. you could also use a http proxy like charles or a packet editor like wpe to make sure nothings messing up if that fails..

    As for what joe said , u just need to urlencode the data if that is needed

    (you need an account to see links)

  4. #4

    Rambo's Avatar
    Joined
    Sep 2013
    Posts
    136
    Userbars
    1
    Thanks
    19
    Thanked
    29/25
    DL/UL
    11/7
    Mentioned
    25 times
    Time Online
    4d 3h 14m
    Avg. Time Online
    1m
    @(you need an account to see links), how would I set a refferer with his wrapper?

  5. #5

    Joined
    Jun 2012
    Posts
    1,699
    Thanks
    876
    Thanked
    2,881/1,142
    DL/UL
    44/1
    Mentioned
    562 times
    Time Online
    118d 6h 45m
    Avg. Time Online
    40m
    Use this post function

    PHP Code:
       public String postString urlString[][] data,String therefferer)  {
          if( 
    url.charAt) == '/' )
             
    url domain url;
          
          try {
             
    HttpURLConnection conn = (HttpURLConnection)( new URLurl.replaceAll" ""%20" ) ).openConnection() );
             
    setRequestPropertiesconn );
             
    conn.setRequestMethod"POST" );
             
    conn.setDoOutputtrue );
             
             
    StringBuilder sb = new StringBuilder();
             
             for( 
    int i 0data[0].lengthi++ )
                
    sb.appendURLEncoder.encodedata[0][i], "UTF-8" ) ).append'=' ).appendURLEncoder.encodedata[1][i], "UTF-8" ) ).append'&' );
             if (
    therefferer != null)
    {
             
    conn.setRequestProperty"Referer"therefferer);
    }
             
    conn.setRequestProperty"Content-Type"rpContentType );
             
    conn.setRequestProperty"Content-Length"Integer.toStringsb.length()-) );
              try (
    PrintWriter out = new PrintWriter( new BufferedWriter( new OutputStreamWriterconn.getOutputStream() ) ) )) {
                  
    out.writesb.substring0sb.length()-) );
              }
             
             
    referer url;
             return 
    readconn );
          } catch( 
    IOException e1 ) {
             
    e1.printStackTrace();
             return 
    null;
          }
       } 

    Then use:
    wrapper.post("http://www.marapets.com/dologin.php",data,"http://www.marapets.com/login.php?do=dologin"); //login

    Something along those lines , u just set a optional param in java (not sure if my codes right for that I dont use java much) and then detect if it has value , if so set the referer header.
    Last edited by DarkByte; 03-11-2014 at 07:08 PM.

  6. #6

    Rambo's Avatar
    Joined
    Sep 2013
    Posts
    136
    Userbars
    1
    Thanks
    19
    Thanked
    29/25
    DL/UL
    11/7
    Mentioned
    25 times
    Time Online
    4d 3h 14m
    Avg. Time Online
    1m
    @(you need an account to see links)

    Still doesn't work.

    Code:
    import urllib,urllib2
    import cookielib
    import re
    import os
    import io,sys
    from getpass import *
    cj = cookielib.CookieJar()
    opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
    opener.addheaders = [
    ('User-Agent', 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.2.11) Gecko/20101012 Firefox/3.6.11'),
    ]
    item = raw_input("User ID:")
    password = raw_input("Password:")
    values = {'id' : item, 'password' : password}
    url = "http://www.marapets.com/dologin.php"
    data = urllib.urlencode(values)
    home = opener.open(url,data)
    This python code I made does. Could it be I havent set cookies? If so, how do I do that?

  7. #7

    Joined
    Dec 2011
    Posts
    95
    Userbars
    4
    Thanks
    161
    Thanked
    172/63
    DL/UL
    32/3
    Mentioned
    87 times
    Time Online
    17d 12h 5m
    Avg. Time Online
    5m
    If you know how to use http sniffer such as Charles Proxy, you can check what the wrapper actually send when you login and see what is wrong with the data.

  8. The Following User Says Thank You to damian002 For This Useful Post:

    DarkByte (03-12-2014)

  9. #8

    Joined
    Jun 2012
    Posts
    1,699
    Thanks
    876
    Thanked
    2,881/1,142
    DL/UL
    44/1
    Mentioned
    562 times
    Time Online
    118d 6h 45m
    Avg. Time Online
    40m
    Charles proxy is amazing , you can pm me if u wanna remove the 15 min (or is it 30) limit from latest version , thats the only thing that annoyed me with it (and the way it breaks on Https)

  10. #9

    Rambo's Avatar
    Joined
    Sep 2013
    Posts
    136
    Userbars
    1
    Thanks
    19
    Thanked
    29/25
    DL/UL
    11/7
    Mentioned
    25 times
    Time Online
    4d 3h 14m
    Avg. Time Online
    1m
    ITs not recording my requests at all?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •