PDA

View Full Version : [JAVA] POST problem with Zer0's Wrapper.



Rambo
03-11-2014, 06:15 PM
So I am trying to use Zer0s Wrapper to make a Marapets Bot.

Zer0's wrapper code I am using:


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-[Only registered and activated users can see links]";

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 {
[Only registered and activated users can see links] conn = ([Only registered and activated users can see links])( 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 {
[Only registered and activated users can see links] conn = ([Only registered and activated users can see links])( 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 {
[Only registered and activated users can see links] conn = ([Only registered and activated users can see links])( 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( [Only registered and activated users can see links] 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( [Only registered and activated users can see links] 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:


<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:


Connection wrapper = new Connection("[Only registered and activated users can see links]");
String[][] data = new String [][] {{"id", "5xxxxxxxx"}, {"password", "pxxxxxx"}};
wrapper.post("[Only registered and activated users can see links]",data); //login


What am I doing wrong? Zachafer DarkByte Josh21227

What I get when I try to login is:


This is the wrong password. Are you sure you have typed it correctly?

[Only registered and activated users can see links]

You will receive a reply within 24 hours

j03
03-11-2014, 06:25 PM
Might have to replace any special characters if they require that. I think Neopets does.

DarkByte
03-11-2014, 06:25 PM
Only thing i can think of is setting the reffer url to

[Only registered and activated users can 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

[Only registered and activated users can see links]

Rambo
03-11-2014, 06:28 PM
DarkByte, how would I set a refferer with his wrapper?

DarkByte
03-11-2014, 07:04 PM
Use this post function



public String post( String url, String[][] data,String therefferer) {
if( url.charAt( 0 ) == '/' )
url = domain + url;

try {
[Only registered and activated users can see links] conn = ([Only registered and activated users can see links])( 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( '&' );
if (therefferer != null)
{
conn.setRequestProperty( "Referer", therefferer);
}
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;
}
}


Then use:
wrapper.post("[Only registered and activated users can see links]",data,"[Only registered and activated users can see links]"); //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.

Rambo
03-11-2014, 07:09 PM
DarkByte

Still doesn't work.



import urllib,urllib2
import cookielib
import re
import os
import io,sys
from getpass import *
cj = cookielib.CookieJar()
opener = urllib2.build_opener(urllib2.[Only registered and activated users can see links](c j))
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 = "[Only registered and activated users can see links]"
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?

damian002
03-11-2014, 10:25 PM
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.

DarkByte
03-12-2014, 01:04 AM
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 :P (and the way it breaks on [Only registered and activated users can see links])

Rambo
03-12-2014, 07:10 AM
ITs not recording my requests at all?