Created
April 8, 2016 09:30
-
-
Save lordzouga/49f2754085375655f972d040dd9c69e7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.support.v7.app.AppCompatActivity; | |
import android.os.Bundle; | |
import android.view.View; | |
import android.widget.Button; | |
import android.widget.EditText; | |
import android.widget.TextView; | |
import java.io.IOException; | |
import java.io.InputStream; | |
import java.net.InetSocketAddress; | |
import java.net.Socket; | |
import java.net.SocketException; | |
public class MainActivity extends AppCompatActivity { | |
public EditText injectionUrl = null; | |
public EditText injectionHost = null; | |
public EditText injectionLineCount = null; | |
public Button connectButton = null; | |
public TextView outputView = null; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
injectionUrl = (EditText) findViewById(R.id.injection_url); | |
injectionHost = (EditText) findViewById(R.id.injection_host); | |
injectionLineCount = (EditText) findViewById(R.id.newlines); | |
outputView = (TextView)findViewById(R.id.output); | |
connectButton = (Button)findViewById(R.id.connect_button); | |
connectButton.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View v) { | |
outputView.setText("Connecting..."); | |
Runnable runnable = new Runnable() { | |
@Override | |
public void run() { | |
InetSocketAddress direct = new InetSocketAddress("104.156.247.105", 8080); | |
Socket remoteSocket = new Socket(); | |
try { | |
remoteSocket.setSoTimeout(30 * 1000); | |
remoteSocket.connect(direct, 5 * 1000); | |
StringBuilder request = new StringBuilder(""); | |
request.append(String.format("%s %s HTTP/1.1\r\n", "CONNECT", injectionUrl.getText())); | |
request.append(String.format("Host: %s", injectionHost.getText())); | |
for (int i = 0; i < Integer.parseInt(injectionLineCount.getText().toString()); i++) { | |
request.append("\r\n"); | |
} | |
remoteSocket.getOutputStream().write(request.toString().getBytes()); | |
InputStream inStream = remoteSocket.getInputStream(); | |
final StringBuilder response = new StringBuilder(""); | |
while (true){ | |
byte b = (byte) inStream.read(); | |
response.append((char)b); | |
if (response.toString().contains("\r\n\r\n")){ | |
break; | |
} | |
} | |
runOnUiThread(new Runnable() { | |
@Override | |
public void run() { | |
outputView.setText(response); | |
} | |
}); | |
} catch (SocketException e) { | |
runOnUiThread(new Runnable() { | |
@Override | |
public void run() { | |
outputView.setText("Connection failed"); | |
} | |
}); | |
e.printStackTrace(); | |
} catch (IOException e) { | |
runOnUiThread(new Runnable() { | |
@Override | |
public void run() { | |
outputView.setText("Connection Failed"); | |
} | |
}); | |
e.printStackTrace(); | |
} | |
} | |
}; | |
new Thread(runnable).start(); | |
} | |
}); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment