Skip to content

Commit

Permalink
enhance rsa exponent logic.
Browse files Browse the repository at this point in the history
  • Loading branch information
whwlsfb committed Mar 17, 2023
1 parent aad70ba commit c1472fd
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 11 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/out/
/target
/.idea
/*.iml
/*.iml
dependency-reduced-pom.xml
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-crypto</artifactId>
<version>5.7.16</version>
<version>5.8.8</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.squareup.okhttp3/okhttp -->
<dependency>
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/burp/BurpExtender.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import burp.utils.BurpCryptoMenuFactory;
import burp.utils.BurpStateListener;
import burp.utils.DictLogManager;
import burp.utils.Utils;
import burp.zuc.ZUCUIHandler;
import cn.hutool.crypto.SecureUtil;
import org.iq80.leveldb.DB;
Expand Down Expand Up @@ -85,8 +86,8 @@ public void registerExtenderCallbacks(IBurpExtenderCallbacks callbacks) {
SecureUtil.disableBouncyCastle();
this.callbacks = callbacks;
this.helpers = callbacks.getHelpers();
this.stdout = new PrintWriter(callbacks.getStdout(), true);
this.stderr = new PrintWriter(callbacks.getStderr(), true);
Utils.stdout = this.stdout = new PrintWriter(callbacks.getStdout(), true);
Utils.stderr = this.stderr = new PrintWriter(callbacks.getStderr(), true);
callbacks.setExtensionName("BurpCrypto v" + version);
callbacks.registerExtensionStateListener(new BurpStateListener(this));
callbacks.registerContextMenuFactory(new BurpCryptoMenuFactory(this));
Expand Down
10 changes: 8 additions & 2 deletions src/main/java/burp/rsa/RsaUIHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,10 @@ public JPanel getPanel() {
modulusText = new JTextField(200);
modulusText.setMaximumSize(modulusText.getPreferredSize());

final JLabel label4 = new JLabel("Exponent(HEX): ");
final JLabel label4 = new JLabel("Exponent: ");
exponentText = new JTextField(200);
exponentText.setMaximumSize(exponentText.getPreferredSize());
exponentText.setText("010001");

final JLabel label5 = new JLabel("X509 Key(Base64): ");
x509Text = new JTextField(200);
Expand All @@ -100,7 +101,12 @@ public JPanel getPanel() {
return;
}
try {
config.Exponent = new BigInteger(exponentText.getText(), 16);
String exponentStr = exponentText.getText();
if (Utils.isNumeric(exponentStr) && Utils.isPrime(Integer.parseInt(exponentStr))) {
config.Exponent = new BigInteger(exponentStr, 10);
} else {
config.Exponent = new BigInteger(exponentStr, 16);
}
} catch (Exception ex) {
JOptionPane.showMessageDialog(mainPanel, "Exponent error!");
return;
Expand Down
5 changes: 1 addition & 4 deletions src/main/java/burp/rsa/RsaUtil.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package burp.rsa;

import burp.utils.OutFormat;
import burp.utils.Utils;
import cn.hutool.crypto.asymmetric.AsymmetricCrypto;
import cn.hutool.crypto.asymmetric.KeyType;
Expand All @@ -9,9 +8,6 @@
import java.security.KeyFactory;
import java.security.spec.RSAPublicKeySpec;

import static burp.utils.Utils.base64;
import static burp.utils.Utils.hex;

public class RsaUtil {
private RsaConfig config;
private AsymmetricCrypto crypto;
Expand All @@ -33,6 +29,7 @@ public String encrypt(byte[] inputArray) throws Exception {
}

private IllegalStateException fail(Exception e) {
e.printStackTrace(Utils.stderr);
return new IllegalStateException(e);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/burp/sm3/SM3IntruderPayloadProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public byte[] processPayload(final byte[] currentPayload, final byte[] originalP
} catch (Exception e) {
this.parent.callbacks.issueAlert(e.toString());
this.parent.stderr.println();
e.printStackTrace(this.parent.stderr);
e.printStackTrace(Utils.stderr);
return null;
}
}
Expand Down
1 change: 1 addition & 0 deletions src/main/java/burp/sm4/SM4Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public String decrypt(String cipherText) {
}

private IllegalStateException fail(Exception e) {
e.printStackTrace(Utils.stderr);
return new IllegalStateException(e);
}
}
Expand Down
21 changes: 21 additions & 0 deletions src/main/java/burp/utils/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.http.client.methods.HttpGet;

import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.math.BigInteger;
import java.security.KeyFactory;
Expand All @@ -21,11 +22,31 @@
public class Utils {
private static MessageDigest md;
private static Random rand = new Random();
public static PrintWriter stdout = null;
public static PrintWriter stderr = null;

public static int GetRandomNumber(int min, int max) {
return rand.nextInt(max - min + 1) + min;
}
public static boolean isPrime(int n) {
if (n <= 1) {
return false;
}

for (int i = 2; i <= Math.sqrt(n); i++) {
if (n % i == 0) {
return false;
}
}

return true;
}
public static boolean isNumeric(String str) {
if (str == null || str.length() == 0) {
return false;
}
return str.matches("^[0-9]+$");
}
public static byte[] HTTPGet(String uri) {
HttpClient client = new HttpClient();
byte[] resp = null;
Expand Down

0 comments on commit c1472fd

Please sign in to comment.