Last active
August 29, 2015 14:17
-
-
Save benjholla/caa03df46e40b90aa4cd to your computer and use it in GitHub Desktop.
A Java implementation of the toy example of the Sendmail Crackaddr flaw created by Thomas Dullien
This file contains 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
package sendmail_crackaddr; | |
/** | |
* A Java implementation of the toy example of the Sendmail Crackaddr flaw created by Thomas Dullien | |
* Source: https://bytebucket.org/mihaila/bindead/wiki/resources/crackaddr-talk.pdf | |
* | |
* Outputs: | |
* Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 200 | |
* at sendmail_crackaddr.SendmailCrackaddr.copyIt(SendmailCrackaddr.java:57) | |
* at sendmail_crackaddr.SendmailCrackaddr.main(SendmailCrackaddr.java:20) | |
* | |
* @author Ben Holland | |
*/ | |
public class SendmailCrackaddr { | |
public static final int BUFFERSIZE = 200; | |
public static void main(String[] args) { | |
String input = "Name Lastname < [email protected] > ()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()"; | |
copyIt(input, input.length()); | |
} | |
public static int copyIt(String input, int length){ | |
char c; | |
char[] localbuf = new char[BUFFERSIZE]; | |
int upperlimit = BUFFERSIZE - 10; | |
boolean quotation = false; | |
boolean roundquote = false; | |
int inputIndex = 0; | |
int outputIndex = 0; | |
while(inputIndex < length){ | |
c = input.charAt(inputIndex++); | |
if((c == '<') && (!quotation)){ | |
quotation = true; | |
upperlimit--; | |
} | |
if((c == '>') && (quotation)){ | |
quotation = false; | |
upperlimit++; | |
} | |
if((c == '(') && (!quotation) && (!roundquote)){ | |
roundquote = true; | |
// upperlimit--; // decrementation was missing in bug | |
} | |
if((c == ')') && (!quotation) && (roundquote)){ | |
roundquote = false; | |
upperlimit++; | |
} | |
// if there is sufficient space in the buffer, write the character | |
if(outputIndex < upperlimit){ | |
localbuf[outputIndex] = c; | |
outputIndex++; | |
} | |
} | |
if(roundquote){ | |
localbuf[outputIndex] = ')'; | |
outputIndex++; | |
} | |
if(quotation){ | |
localbuf[outputIndex] = '>'; | |
outputIndex++; | |
} | |
return outputIndex; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment