From 9b7cd27796647f7964fd38a913d39401dd430d0b Mon Sep 17 00:00:00 2001 From: 0chen Date: Sat, 22 Jan 2022 19:49:44 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8A=9B=E5=BC=83=E8=BF=87=E6=9C=9F=E7=9A=84?= =?UTF-8?q?=E6=97=A7=E4=BE=9D=E8=B5=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 抛弃过期的旧依赖,引用新的依赖 修复一处代码不规范问题 --- .gitignore | 3 +- build.gradle | 4 +- src/burp/BurpExtender.java | 6 +- src/burp/Config.java | 26 ++ src/burp/fuction/CodeMode.kt | 33 ++ src/burp/fuction/CoreFunc.kt | 550 ++++++++++++++++++++------------- src/burp/fuction/PythonFunc.kt | 2 +- src/burp/json/PluginsJson.kt | 13 +- src/burp/json/SettingJson.kt | 11 +- src/burp/ui/About.java | 13 +- src/burp/ui/DecodePanel.java | 87 +++--- src/burp/ui/MainUi.java | 1 - src/burp/ui/PluginsConfig.java | 10 +- src/burp/ui/SettingConfig.java | 4 +- 14 files changed, 462 insertions(+), 301 deletions(-) create mode 100644 src/burp/Config.java create mode 100644 src/burp/fuction/CodeMode.kt diff --git a/.gitignore b/.gitignore index e48a015..b774abf 100644 --- a/.gitignore +++ b/.gitignore @@ -151,4 +151,5 @@ gradle-app.setting # End of https://www.toptal.com/developers/gitignore/api/macos,gradle,intellij+all #Users -test \ No newline at end of file +test +*.jfd \ No newline at end of file diff --git a/build.gradle b/build.gradle index 56e9da0..33b080c 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,5 @@ group 'org.ctfcracktools' -version '1.1.1' +version '1.1.2' buildscript { ext.kotlin_version = '1.4.10' @@ -37,7 +37,7 @@ dependencies { compile group: 'org.python', name: 'jython', version: '2.7.1b3' compile group: 'com.google.code.gson', name: 'gson', version: '2.8.9' compile group: 'commons-codec', name: 'commons-codec', version: '1.10' - compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.9' + compile group: 'org.apache.commons', name: 'commons-text', version: '1.9' compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version" } diff --git a/src/burp/BurpExtender.java b/src/burp/BurpExtender.java index f73f189..129411f 100644 --- a/src/burp/BurpExtender.java +++ b/src/burp/BurpExtender.java @@ -6,6 +6,9 @@ import burp.ui.MainUi; +/** + * @author linchen + */ public class BurpExtender implements IBurpExtender, ITab { private IBurpExtenderCallbacks callbacks; private static PrintWriter stdout; @@ -14,8 +17,7 @@ public class BurpExtender implements IBurpExtender, ITab { public void registerExtenderCallbacks(final IBurpExtenderCallbacks callbacks) { this.callbacks = callbacks; - String version = "1.1.1"; - callbacks.setExtensionName(String.format("DaE (%s) - CTFCrackTools's Burpsuite Plugin - Decode and Encode", version)); + callbacks.setExtensionName(String.format("DaE (%s) - CTFCrackTools's Burpsuite Plugin - Decode and Encode", Config.VERSION)); // 定义输出 stdout = new PrintWriter(callbacks.getStdout(), true); stdout.println("@Author: 0chencc"); diff --git a/src/burp/Config.java b/src/burp/Config.java new file mode 100644 index 0000000..127831f --- /dev/null +++ b/src/burp/Config.java @@ -0,0 +1,26 @@ +package burp; + +import burp.fuction.PythonFunc; +import burp.fuction.PythonFunc; + +import java.io.File; + +/** + * @author linchen + */ +public class Config { + public final static String VERSION = "1.1.2"; + public final static String SLOGAN = ""; + public final static String ABOUT = + "Author:0chen(@0chencc)\n" + + "Twitter:@0chencc\n" + + "GitHub:https://github.com/0Chencc\n" + + "Wechat Official Accounts(公众号):XizhouPoetry\n" + + "Repository Url:https://github.com/0Chencc/CTFCrackTools\n" + + "米斯特安全团队招CTF选手,有意向联系admin@hi-ourlife.com"; + public final static File PLUGIN_FILE = new File("ctfcracktools_plugins.json"); + public final static File SETTING_FILE = new File("ctfcracktools_setting.json"); + + public static PythonFunc pyFunc = new PythonFunc(); + +} diff --git a/src/burp/fuction/CodeMode.kt b/src/burp/fuction/CodeMode.kt new file mode 100644 index 0000000..4dff8cc --- /dev/null +++ b/src/burp/fuction/CodeMode.kt @@ -0,0 +1,33 @@ +package ctfcracktools.fuction + +class CodeMode { + companion object{ + const val CRYPTO_FENCE = "Fence" + const val CRYPTO_CAESAR = "CaesarCode" + const val CRYPTO_PIG = "PigCode" + const val CRYPTO_ROT13 = "ROT13" + const val CRYPTO_HEX_2_STRING = "Hex2String" + const val CRYPTO_STRING_2_HEX = "String2Hex" + const val CRYPTO_UNICODE_2_ASCII = "Unicode2Ascii" + const val CRYPTO_ASCII_2_UNICODE = "Ascii2Unicode" + const val CRYPTO_REVERSE = "Reverse" + + const val DECODE_MORSE = "MorseDecode" + const val DECODE_BACON = "BaconDecode" + const val DECODE_BASE64 = "Base64Decode" + const val DECODE_BASE32 = "BASE32Decode" + const val DECODE_URL = "UrlDecode" + const val DECODE_UNICODE = "UnicodeDecode" + const val DECODE_HTML = "HtmlDecode" + const val DECODE_VIGENERE = "VigenereDeCode" + + const val ENCODE_MORSE = "MorseEncode" + const val ENCODE_BACON = "BaconEncode" + const val ENCODE_BASE64 = "Base64Encode" + const val ENCODE_BASE32 = "Base32Encode" + const val ENCODE_URL = "UrlEncode" + const val ENCODE_UNICODE = "UnicodeEncode" + const val ENCODE_HTML = "HtmlEncode" + const val ENCODE_VIGENERE = "VigenereEnCode" + } +} \ No newline at end of file diff --git a/src/burp/fuction/CoreFunc.kt b/src/burp/fuction/CoreFunc.kt index 5908a0c..98bef15 100644 --- a/src/burp/fuction/CoreFunc.kt +++ b/src/burp/fuction/CoreFunc.kt @@ -1,48 +1,67 @@ -package burp.fuction +package org.ctfcracktools.fuction +import ctfcracktools.fuction.CodeMode import org.apache.commons.codec.binary.Base32 import org.apache.commons.codec.binary.Base64.* -import org.apache.commons.lang3.StringEscapeUtils; -import org.apache.commons.lang3.StringUtils +import org.apache.commons.text.StringEscapeUtils import java.net.URLDecoder import java.net.URLEncoder import java.util.* import java.util.regex.Matcher import java.util.regex.Pattern +import javax.swing.JOptionPane + /** * @author 林晨0chencc * @since 2017/12/2 - * @version 1.0.0 + * @version 1.0.2 */ class CoreFunc{ + /** + * 主函数 + * @param input 需要加密/解密的字符串传入 + * @param type 加密类型 + * @return String 编码后的结果 + */ fun callFunc(input:String,type:String): String? { - val funcMap = mutableMapOf("Fence" to ::fence, - "CaesarCode" to ::caesar, - "PigCode" to ::pigCode, - "Rot13" to ::rot13, - "Hex2String" to ::hextoString, - "String2Hex" to ::stringtoHex, - "Unicode2Ascii" to ::unicodeToAscii, - "Ascii2Unicode" to ::asciiToUnicode, - "Reverse" to ::reverse, - "MorseDecode" to ::morseDecode, - "BaconDecode" to ::baconCodeDecode, - "Base64Decode" to ::base64de, - "Base32Decode" to ::base32de, - "UrlDecode" to ::urlDecoder, - "UnicodeDecode" to ::unicodeDecode, - "MorseEncode" to ::morseEncode, - "BaconEncode" to ::baconCodeEncode, - "Base64Encode" to ::base64en, - "Base32Encode" to ::base32en, - "UrlEncode" to ::urlEncoder, - "UnicodeEncode" to ::unicodeEncode, - "HTMLEncode" to ::htmlEncode, - "HTMLDecode" to ::htmlDecode) + val funcMap = mutableMapOf( + CodeMode.CRYPTO_FENCE to ::fence, + CodeMode.CRYPTO_CAESAR to ::caesar, + CodeMode.CRYPTO_PIG to ::pigCode, + CodeMode.CRYPTO_ROT13 to ::rot13, + CodeMode.CRYPTO_HEX_2_STRING to ::hextoString, + CodeMode.CRYPTO_STRING_2_HEX to ::stringtoHex, + CodeMode.CRYPTO_UNICODE_2_ASCII to ::unicodeToAscii, + CodeMode.CRYPTO_ASCII_2_UNICODE to ::asciiToUnicode, + CodeMode.CRYPTO_REVERSE to ::reverse, + + CodeMode.DECODE_MORSE to ::morseDecode, + CodeMode.DECODE_BACON to ::baconCodeDecode, + CodeMode.DECODE_BASE64 to ::base64de, + CodeMode.DECODE_BASE32 to ::base32de, + CodeMode.DECODE_URL to ::urlDecoder, + CodeMode.DECODE_UNICODE to ::unicodeDecode, + CodeMode.DECODE_HTML to ::htmlDecode, + CodeMode.DECODE_VIGENERE to ::vigenereDeCode, + + CodeMode.ENCODE_MORSE to ::morseEncode, + CodeMode.ENCODE_BACON to ::baconCodeEncode, + CodeMode.ENCODE_BASE64 to ::base64en, + CodeMode.ENCODE_BASE32 to ::base32en, + CodeMode.ENCODE_URL to ::urlEncoder, + CodeMode.ENCODE_UNICODE to ::unicodeEncode, + CodeMode.ENCODE_HTML to ::htmlEncode, + CodeMode.ENCODE_VIGENERE to ::vigenereEnCode,) return funcMap[type]?.let { it(input) } } - fun fence(input: String):String { + + /** + * 栅栏密码 + * @param input 待加密解密的字符串 + * @return String + */ + private fun fence(input: String):String { val str:Array = arrayOfNulls(1024) val x = IntArray(1024) val result = StringBuffer() @@ -79,7 +98,7 @@ class CoreFunc{ } } } - if (a !== 0) { + if (a != 0) { (0 until a).forEach { it -> result.append(" " + x[it]) } (0 until a).forEach { i -> result.append("${i+1}:") @@ -96,12 +115,18 @@ class CoreFunc{ } } return result.toString() - }//栅栏密码 - fun caesar(input:String):String{ + } + + /** + * 凯撒密码/Caesar Code + * @param input 待加密解密的字符串 + * @return String + */ + private fun caesar(input:String):String{ val word:CharArray=input.toCharArray() val result = StringBuffer() (0 until 26).forEach { - (0 until word.size).forEach { j -> + (word.indices).forEach { j -> if (word[j].isUpperCase()){ if(word[j]=='Z') word[j]='A' else word[j] = (word[j].toInt() + 1).toChar() }else if(word[j].isLowerCase()){ @@ -111,85 +136,111 @@ class CoreFunc{ result.append(word+'\n') } return result.toString() - }//凯撒密码 - fun vigenereEnCode(input:CharArray,key:CharArray): String { + } + + /** + * 维吉利亚密码 + * @param input 待加解密的字符串 + * @param mode VIGENERE_MODE_DECODE为解密 VIGENERE_MODE_DECODE为加密 + * @return String + */ + private fun vigenereCode(input:String,mode:String):String{ + val pass = input.toCharArray() + val key = JOptionPane.showInputDialog("Please input key").toCharArray() var i = 0 var j:Int var q = 0 var k:Int var m:Int - return StringBuilder() + when(mode){ + CodeMode.DECODE_VIGENERE -> return StringBuilder() .let{ - result -> - while (i + while (i { + pass[i].isUpperCase() -> { j = q%key.size k = UpperCase.indexOf(key[j].toUpperCase()) - m = UpperCase.indexOf(input[i]) + m = UpperCase.indexOf(pass[i]) result.append(UpperCase[(m+k)%26]) q++ } - input[i].isLowerCase() -> { + pass[i].isLowerCase() -> { j = q%key.size k = LowerCase.indexOf(key[j].toLowerCase()) - m = LowerCase.indexOf(input[i]) + m = LowerCase.indexOf(pass[i]) result.append(LowerCase[(m+k)%26]) q++ } - else -> result.append(input[i]) + else -> result.append(pass[i]) } i++ } result } .toString() - } - fun vigenereDeCode(input:CharArray,key: CharArray):String{ - var i = 0 - var j:Int - var q = 0 - var k:Int - var m:Int - return StringBuilder() + CodeMode.ENCODE_VIGENERE -> return StringBuilder() .let{ - result -> - while (i + while (i { + pass[i].isUpperCase() -> { j = q%key.size k = UpperCase.indexOf(key[j].toUpperCase()) - m = UpperCase.indexOf(input[i]) + m = UpperCase.indexOf(pass[i]) if(m { + pass[i].isLowerCase() -> { j = q%key.size k = LowerCase.indexOf(key[j].toLowerCase()) - m = LowerCase.indexOf(input[i]) + m = LowerCase.indexOf(pass[i]) if(m result.append(input[i]) + else -> result.append(pass[i]) } i++ } result } .toString() + else -> return "None" + } } - fun pigCode(input:String):String{ + + /** + * 维吉利亚密码加密 依赖vigenereCode + * @param input 待加密的字符串 + * @return String + */ + + private fun vigenereEnCode(input:String): String = vigenereCode(input, CodeMode.ENCODE_VIGENERE) + + /** + * 维吉利亚解密 依赖vigenereCode + * @param input 待解密的字符串 + * @return String + */ + private fun vigenereDeCode(input:String):String = vigenereCode(input, CodeMode.DECODE_VIGENERE) + + /** + * 猪圈密码 + * @param input 待解密的字符串 + * @return String + */ + private fun pigCode(input:String):String{ val result = StringBuffer() val keymap= mapOf('A' to 'J','B' to 'K','C' to 'L','D' to 'M', - 'E' to 'N','F' to 'O','G' to 'P','H' to 'Q','I' to 'R','J' to 'A','K' to 'B','L' to 'C', - 'M' to 'D','N' to 'E','O' to 'F','P' to 'G','Q' to 'H','R' to 'I','S' to 'W','T' to 'X', - 'U' to 'Y','V' to 'Z','W' to 'S','X' to 'T') + 'E' to 'N','F' to 'O','G' to 'P','H' to 'Q','I' to 'R','J' to 'A','K' to 'B','L' to 'C', + 'M' to 'D','N' to 'E','O' to 'F','P' to 'G','Q' to 'H','R' to 'I','S' to 'W','T' to 'X', + 'U' to 'Y','V' to 'Z','W' to 'S','X' to 'T') val word = input.toCharArray() - for (i in 0 until word.size){ + for (i in word.indices){ if (word[i].isUpperCase()){ result.append(keymap.get(word[i])!!) }else if(word[i].isLowerCase()){ @@ -199,8 +250,14 @@ class CoreFunc{ } } return result.toString() - }//猪圈密码 - fun rot13(input:String):String{ + } + + /** + * ROT13 + * @param input 待编码的字符串 + * @return String + */ + private fun rot13(input:String):String{ var word = input.toCharArray() val result = StringBuffer() for (i in 0 until word.size){ @@ -213,96 +270,132 @@ class CoreFunc{ result.append(word[i]) } return result.toString() - }//Rot13 - fun baconCodeEncode(input:String):String{ + } + + /** + * 培根密码加密 + * @param input 待加密的字符串 + * @return String + */ + private fun baconCodeEncode(input:String):String{ val keymap = mapOf("A" to "aaaaa","B" to "aaaab","C" to "aaaba", - "D" to "aaabb","E" to "aabaa","F" to "aabab","G" to "aabba","H" to "aabbb","I" to "abaaa", - "J" to "abaab","K" to "ababa","L" to "ababb","M" to "abbaa","N" to "abbab","O" to "abbba", - "P" to "abbbb","Q" to "baaaa","R" to "baaab","S" to "baaba","T" to "baabb","U" to "babaa", - "V" to "babab","W" to "babba","X" to "babbb","Y" to "bbaaa","Z" to "bbaab","a" to "AAAAA", - "b" to "AAAAB","c" to "AAABA","d" to "AAABB","e" to "AABAA","f" to "AABAB","g" to "AABBA", - "h" to "AABBB","i" to "ABAAA","j" to "ABAAB","k" to "ABABA","l" to "ABABB","m" to "ABBAA", - "n" to "ABBAB","o" to "ABBBA","p" to "ABBBB","q" to "BAAAA", - "r" to "BAAAB","s" to "BAABA","t" to "BAABB","u" to "BABAA","v" to "BABAB","w" to "BABBA", - "x" to "BABBB","y" to "BBAAA","z" to "BBAAB") + "D" to "aaabb","E" to "aabaa","F" to "aabab","G" to "aabba","H" to "aabbb","I" to "abaaa", + "J" to "abaab","K" to "ababa","L" to "ababb","M" to "abbaa","N" to "abbab","O" to "abbba", + "P" to "abbbb","Q" to "baaaa","R" to "baaab","S" to "baaba","T" to "baabb","U" to "babaa", + "V" to "babab","W" to "babba","X" to "babbb","Y" to "bbaaa","Z" to "bbaab","a" to "AAAAA", + "b" to "AAAAB","c" to "AAABA","d" to "AAABB","e" to "AABAA","f" to "AABAB","g" to "AABBA", + "h" to "AABBB","i" to "ABAAA","j" to "ABAAB","k" to "ABABA","l" to "ABABB","m" to "ABBAA", + "n" to "ABBAB","o" to "ABBBA","p" to "ABBBB","q" to "BAAAA", + "r" to "BAAAB","s" to "BAABA","t" to "BAABB","u" to "BABAA","v" to "BABAB","w" to "BABBA", + "x" to "BABBB","y" to "BBAAA","z" to "BBAAB") return StringBuilder() - .let{ + .let{ result -> - if(is26word(input)) { - splitNum(input,1).forEach {result.append(keymap[it])} - }else{ - result.append("有字符不属于26字母其中") - } - result + if(is26word(input)) { + splitNum(input,1).forEach {result.append(keymap[it])} + }else{ + result.append("有字符不属于26字母其中") } - .toString() - }//培根密码加密 - fun baconCodeDecode(input: String):String{ + result + } + .toString() + } + + /** + * 培根密码解密 + * @param input 待加密的字符串 + * @return String + */ + private fun baconCodeDecode(input: String):String{ val keymap = mapOf("aaaaa" to 'A',"aaaab" to 'B',"aaaba" to 'C', - "aaabb" to 'D',"aabaa" to 'E',"aabab" to 'F',"aabba" to 'G',"aabbb" to 'H',"abaaa" to 'I', - "abaab" to 'J',"ababa" to 'K',"ababb" to 'L',"abbaa" to 'M',"abbab" to 'N',"abbba" to 'O', - "abbbb" to 'P',"baaaa" to 'Q',"baaab" to 'R',"baaba" to 'S',"baabb" to 'T',"babaa" to 'U', - "babab" to 'V',"babba" to 'W',"babbb" to 'X',"bbaaa" to 'Y',"bbaab" to 'Z',//UpperCase大写字符 - "AAAAA" to 'a',"AAAAB" to 'b',"AAABA" to 'c',"AAABB" to 'd',"AABAA" to 'e',"AABAB" to 'f', - "AABBA" to 'g',"AABBB" to 'h',"ABAAA" to 'i',"ABAAB" to 'j',"ABABA" to 'k', - "ABABB" to 'l',"ABBAA" to 'm',"ABBAB" to 'n',"ABBBA" to 'o', "ABBBB" to 'p',"BAAAA" to 'q', - "BAAAB" to 'r',"BAABA" to 's',"BAABB" to 't',"BABAA" to 'u',"BABAB" to 'v',"BABBA" to 'w', - "BABBB" to 'x',"BBAAA" to 'y',"BBAAB" to 'z' + "aaabb" to 'D',"aabaa" to 'E',"aabab" to 'F',"aabba" to 'G',"aabbb" to 'H',"abaaa" to 'I', + "abaab" to 'J',"ababa" to 'K',"ababb" to 'L',"abbaa" to 'M',"abbab" to 'N',"abbba" to 'O', + "abbbb" to 'P',"baaaa" to 'Q',"baaab" to 'R',"baaba" to 'S',"baabb" to 'T',"babaa" to 'U', + "babab" to 'V',"babba" to 'W',"babbb" to 'X',"bbaaa" to 'Y',"bbaab" to 'Z',//UpperCase大写字符 + "AAAAA" to 'a',"AAAAB" to 'b',"AAABA" to 'c',"AAABB" to 'd',"AABAA" to 'e',"AABAB" to 'f', + "AABBA" to 'g',"AABBB" to 'h',"ABAAA" to 'i',"ABAAB" to 'j',"ABABA" to 'k', + "ABABB" to 'l',"ABBAA" to 'm',"ABBAB" to 'n',"ABBBA" to 'o', "ABBBB" to 'p',"BAAAA" to 'q', + "BAAAB" to 'r',"BAABA" to 's',"BAABB" to 't',"BABAA" to 'u',"BABAB" to 'v',"BABBA" to 'w', + "BABBB" to 'x',"BBAAA" to 'y',"BBAAB" to 'z' ) return StringBuilder() - .let{ + .let{ result -> - var inputnew:String = "" - if(isBacon(input)){ - inputnew = input.replace(" ","") - splitNum(inputnew,5,"[ab]{5}").forEach { result.append(keymap[it]) } - }else{ - result.append("并非是培根密码") - } - result + if(isBacon(input)){ + val inputnew = input.replace(" ","") + splitNum(inputnew,5,"[ab]{5}").forEach { result.append(keymap[it]) } + }else{ + result.append("并非是培根密码") } - .toString() - }//培根密码解密 - fun base64de(input: String):String = String(decodeBase64(input))//Base64解码 - fun base64en(input: String):String = encodeBase64String(input.toByteArray())//Base64编码 - fun base32de(input:String):String = String(Base32().decode(input))//Base32解码 - fun base32en(input:String):String = Base32().encodeAsString(input.toByteArray())//Base32编码 - fun hextoString(input:String):String{ + result + } + .toString() + } + + private fun base64de(input: String):String = String(decodeBase64(input)) + private fun base64en(input: String):String = encodeBase64String(input.toByteArray()) + private fun base32de(input:String):String = String(Base32().decode(input)) + private fun base32en(input:String):String = Base32().encodeAsString(input.toByteArray()) + + /** + * 16进制转字符串 + * @param input 待编码的字符串 + * @return String + */ + private fun hextoString(input:String):String{ return StringBuilder() - .let{ + .let{ result -> - (0 until input.length-1 step 2) - .map{ input.substring(it, it+2) } - .map { Integer.parseInt(it,16) } - .forEach { result.append(it.toChar()) } - result - } - .toString() - }//16进制转字符串 - fun stringtoHex(input:String):String{ + (0 until input.length-1 step 2) + .map{ input.substring(it, it+2) } + .map { Integer.parseInt(it,16) } + .forEach { result.append(it.toChar()) } + result + } + .toString() + } + + /** + * 字符串转16进制 + * @param input 待编码的字符串 + * @return String + */ + private fun stringtoHex(input:String):String{ return StringBuilder() - .let{ + .let{ result -> - input.toCharArray().forEach {result.append(Integer.toHexString(it.toInt())) } - result - } - .toString() - }//字符串转16进制 - fun morseEncode(input: String):String { + input.toCharArray().forEach {result.append(Integer.toHexString(it.toInt())) } + result + } + .toString() + } + + /** + * 摩斯电码编码 + * @param input 待编码的字符串 + * @return String + */ + private fun morseEncode(input: String):String { return StringBuilder() - .let{ + .let{ result -> - input.toLowerCase().toCharArray().forEach { - when { - isChar(it) -> result.append(morseCharacters[(it - 'a')]+" ") - isDigit(it) -> result.append(morseDigits[(it - '0')]+" ") - } + input.toLowerCase().toCharArray().forEach { + when { + isChar(it) -> result.append(morseCharacters[(it - 'a')]+" ") + isDigit(it) -> result.append(morseDigits[(it - '0')]+" ") } - result } - .toString() - }//摩斯密码加密 - fun morseDecode(input:String):String{ + result + } + .toString() + } + + /** + * 摩斯密码解码 + * @param input 待解码的字符串 + * @return String + */ + private fun morseDecode(input:String):String{ initMorseTable() val morse=format(input) val st=StringTokenizer(morse) @@ -311,50 +404,69 @@ class CoreFunc{ result.append(htMorse[st.nextToken()]) } return result.toString() - }//摩斯密码解码 - fun urlEncoder(input: String):String = URLEncoder.encode(input,"utf-8").replace("+","%20")//Url编码加密 - fun urlDecoder(input: String):String = URLDecoder.decode(input,"utf-8")//Url编码解密 - fun unicodeEncode(input: String):String{ + } + + private fun urlEncoder(input: String):String = URLEncoder.encode(input,"utf-8").replace("+","%20")//Url编码加密 + private fun urlDecoder(input: String):String = URLDecoder.decode(input,"utf-8")//Url编码解密 + private fun unicodeEncode(input: String):String{ return StringBuilder() - .let { + .let { result -> - input.toCharArray().forEach {result.append("\\u"+Integer.toHexString(it.toInt())) } - result - } - .toString() - }//Unicode编码 - fun unicodeDecode(input: String):String{ + input.toCharArray().forEach {result.append("\\u"+Integer.toHexString(it.toInt())) } + result + } + .toString() + } + private fun unicodeDecode(input: String):String{ return StringBuilder() - .let{ + .let{ result -> - val hex=input.split("\\u") - (1 until hex.size) - .map { Integer.parseInt(hex[it], 16) } - .forEach { result.append(it.toChar()) } - result - } - .toString() - }//Unicode解码 - fun unicodeToAscii(input:String):String{ + val hex=input.split("\\u") + (1 until hex.size) + .map { Integer.parseInt(hex[it], 16) } + .forEach { result.append(it.toChar()) } + result + } + .toString() + } + + /** + * Unicode编码转Ascii编码 + * @param input 待编码的字符串 + * @return String + */ + private fun unicodeToAscii(input:String):String{ return StringBuilder() - .let{ + .let{ result -> - val pout = Pattern.compile("\\&\\#(\\d+)").matcher(input) - while (pout.find()){ result.append(Integer.valueOf(pout.group(1)).toInt().toChar()) } - result - } - .toString() - }//Unicode编码转换为Ascii编码 - fun asciiToUnicode(input: String):String{ + val pout = Pattern.compile("\\&\\#(\\d+)").matcher(input) + while (pout.find()){ result.append(Integer.valueOf(pout.group(1)).toInt().toChar()) } + result + } + .toString() + } + + /** + * Ascii编码转Unicode编码 + * @param input 待编码的字符串 + * @return String + */ + private fun asciiToUnicode(input: String):String{ return StringBuilder() - .let { + .let { result -> - input.toCharArray().forEach { result.append("&#"+it.toInt()+";")} - result - } - .toString() + input.toCharArray().forEach { result.append("&#"+it.toInt()+";")} + result + } + .toString() } - fun reverse(input:String):String{ + + /** + * 字符翻转,顾名思义 + * @param input 待翻转的字符串 + * @return String + */ + private fun reverse(input:String):String{ val result = StringBuilder() val tmp = input.toCharArray() var a=tmp.size-1 @@ -363,60 +475,56 @@ class CoreFunc{ a-=1 } return result.toString() - }//字符翻转 -/* fun HillCodeEncode(input:String,key:String):String{ - val keymatrix:CharArray = key.split(" ") as CharArray - var tmp[]:Array - when{ - keymatrix.size/4 == 0 -> - 0 until keymatrix.size%4.forEach{ - - } + } + /* fun HillCodeEncode(input:String,key:String):String{ + val keymatrix:CharArray = key.split(" ") as CharArray + var tmp[]:Array + when{ + keymatrix.size/4 == 0 -> + 0 until keymatrix.size%4.forEach{ - } - return StringBuffer() - .let { - result-> + } - } - .toString() - }*/ - fun htmlEncode(input:String): String? = StringEscapeUtils.escapeHtml4(input) - fun htmlDecode(input:String):String = StringEscapeUtils.unescapeHtml4(input) - /* 调用Python的插件 */ + } + return StringBuffer() + .let { + result-> + } + .toString() + }*/ + private fun htmlEncode(input:String): String = StringEscapeUtils.escapeHtml4(input) + private fun htmlDecode(input:String):String = StringEscapeUtils.unescapeHtml4(input) /* 内置方法/内置常量 */ - val UpperCase:String ="ABCDEFGHIJKLMNOPQRSTUVWXYZ" - val LowerCase:String = "abcdefghijklmnopqrstuvwxyz" - val SplitString = {//多次切割字符串 - input:String -> - val tmp = input.split(",") - val result = StringBuilder() - tmp.forEach{ - val tmp_1 = it.split(" to ") - result.append(tmp_1[1]+" to "+tmp_1[0]+",") - } - result.toString() - } - fun splitNum(input:String,Num:Int):Array{ - val str:Array = arrayOfNulls(input.length/Num) - (1..input.length/Num).forEach { i->str.set(i-1,input.substring(i*Num-Num,i*Num)) } + private val UpperCase:String ="ABCDEFGHIJKLMNOPQRSTUVWXYZ" + private val LowerCase:String = "abcdefghijklmnopqrstuvwxyz" +// private val SplitString = {//多次切割字符串 +// input:String -> +// val tmp = input.split(",") +// val result = StringBuilder() +// tmp.forEach{ +// val tmp_1 = it.split(" to ") +// result.append(tmp_1[1]+" to "+tmp_1[0]+",") +// } +// result.toString() +// } + private fun splitNum(input:String,num:Int):Array{ + val str:Array = arrayOfNulls(input.length/num) + (1..input.length/num).forEach { i->str.set(i-1,input.substring(i*num-num,i*num)) } return str } - fun splitNum(input:String,Num:Int,p:String):Array{ - val r:Pattern = Pattern.compile(p) + private fun splitNum(input:String,num:Int,pattern:String):Array{ + val r:Pattern = Pattern.compile(pattern) val m: Matcher = r.matcher(input) var input_m = "" var a = true while (a){ if(!m.find()) a=false else input_m += m.group() } - val str:Array = arrayOfNulls(input_m.length/Num) - (1..input_m.length/Num).forEach { i->str.set(i-1,input_m.substring(i*Num-Num,i*Num)) } - return str + return splitNum(input_m,num) } val isBacon = { - input:String -> + input:String -> var tmp:Boolean = false input.toCharArray().forEach { tmp = (it=='A'||it=='B')||(it == 'a'||it=='b') @@ -424,7 +532,7 @@ class CoreFunc{ tmp } val is26word = { - input:String -> + input:String -> var tmp = false input.toCharArray().forEach { tmp = isChar(it) @@ -432,23 +540,23 @@ class CoreFunc{ tmp } var htMorse: Hashtable = Hashtable() - fun initMorseTable(){ + private fun initMorseTable(){ (0..25).forEach { i -> htMorse.put(morseCharacters[i], Character.valueOf((65+i).toChar())) } (0..9).forEach { i -> htMorse.put(morseDigits[i], Character.valueOf((48+i).toChar())) } } val isChar = {c:Char -> c.isLowerCase()||c.isUpperCase()} val isDigit = {c:Char -> (c >='0')&&(c <= '9')} /* moresCode */ - val morseCharacters = arrayOf(".-", "-...", "-.-.", "-..", ".", "..-.", "--.", "....", "src", ".---", - "-.-", ".-..", "--", "-.", "---", ".--.", "--.-", ".-.", "...", "-", "..-", "...-", ".--", "-..-", "-.--", - "--..") - val morseDigits = arrayOf("-----", ".----", "..---", "...--", "....-", ".....", "-....", "--...", - "---..", "----.") + private val morseCharacters = arrayOf(".-", "-...", "-.-.", "-..", ".", "..-.", "--.", "....", "src", ".---", + "-.-", ".-..", "--", "-.", "---", ".--.", "--.-", ".-.", "...", "-", "..-", "...-", ".--", "-..-", "-.--", + "--..") + private val morseDigits = arrayOf("-----", ".----", "..---", "...--", "....-", ".....", "-....", "--...", + "---..", "----.") val format = { - input:String-> + input:String-> val word = input.toCharArray() val result = StringBuilder() - for(i in 0 .. word.size-1){ + for(i in word.indices){ when{ word[i] == '\n' -> word[i]=' ' word[i] == '.' -> { diff --git a/src/burp/fuction/PythonFunc.kt b/src/burp/fuction/PythonFunc.kt index 23ca1ff..6a1796e 100644 --- a/src/burp/fuction/PythonFunc.kt +++ b/src/burp/fuction/PythonFunc.kt @@ -87,4 +87,4 @@ class PythonFunc { fun getAuthorInfo(file:String):Map { loadFile(file) return execFunc(loadPythonFunc(interpreter,"author_info")) as Map} - } \ No newline at end of file +} \ No newline at end of file diff --git a/src/burp/json/PluginsJson.kt b/src/burp/json/PluginsJson.kt index e340f45..1b5fd7b 100644 --- a/src/burp/json/PluginsJson.kt +++ b/src/burp/json/PluginsJson.kt @@ -1,21 +1,20 @@ -package burp.json +package org.ctfcracktools.json import com.google.gson.Gson import com.google.gson.GsonBuilder import com.google.gson.reflect.TypeToken +import burp.Config import java.io.* import kotlin.collections.ArrayList class PluginsJson { - private var jsonFile = File("ctfcracktools_plugins.json") - /** * 初始化 */ init{ if(!isJson()){ val initPlugins = arrayListOf>() - jsonFile.createNewFile() + Config.PLUGIN_FILE.createNewFile() writeJson(initPlugins) } } @@ -25,7 +24,7 @@ class PluginsJson { * @return 返回一个Map的ArrayList插件列表 */ fun parseJson(): ArrayList> { - val pluginsReader = BufferedReader(FileReader(jsonFile)) + val pluginsReader = BufferedReader(FileReader(Config.PLUGIN_FILE)) return Gson().fromJson(pluginsReader, object : TypeToken>>() {}.type) } @@ -59,7 +58,7 @@ class PluginsJson { */ fun writeJson(plugins:ArrayList>){ val gson = GsonBuilder().setPrettyPrinting().create() - val writer = BufferedWriter(FileWriter(jsonFile)) + val writer = BufferedWriter(FileWriter(Config.PLUGIN_FILE)) writer.write(gson.toJson(plugins)) writer.flush() } @@ -68,5 +67,5 @@ class PluginsJson { * 判断是否为配置文件 * @return Boolean */ - fun isJson():Boolean = jsonFile.isFile && jsonFile.exists() + fun isJson():Boolean = Config.PLUGIN_FILE.isFile && Config.PLUGIN_FILE.exists() } \ No newline at end of file diff --git a/src/burp/json/SettingJson.kt b/src/burp/json/SettingJson.kt index c2ccbfd..d896069 100644 --- a/src/burp/json/SettingJson.kt +++ b/src/burp/json/SettingJson.kt @@ -3,14 +3,14 @@ package burp.json import com.google.gson.Gson import com.google.gson.GsonBuilder import com.google.gson.reflect.TypeToken +import burp.Config import java.io.* class SettingJson { - private var settingFile = File("ctfcracktools_setting.json") init { if(!isJson()){ val initSetting = mapOf("jython" to "") - settingFile.createNewFile() + Config.SETTING_FILE.createNewFile() writeJson(initSetting) } } @@ -20,8 +20,9 @@ class SettingJson { * @return Map */ fun parseJson():Map{ - val settingReader = BufferedReader(FileReader(settingFile)) + val settingReader = BufferedReader(FileReader(Config.SETTING_FILE)) return Gson().fromJson(settingReader, object : TypeToken>() {}.type) + ?: return mapOf(pair = "jython" to "") } /** @@ -30,9 +31,9 @@ class SettingJson { */ fun writeJson(setting:Map){ val gson = GsonBuilder().setPrettyPrinting().create() - val writer = BufferedWriter(FileWriter(settingFile)) + val writer = BufferedWriter(FileWriter(Config.SETTING_FILE)) writer.write(gson.toJson(setting)) writer.flush() } - fun isJson():Boolean = settingFile.isFile && settingFile.exists() + fun isJson():Boolean = Config.SETTING_FILE.isFile && Config.SETTING_FILE.exists() } \ No newline at end of file diff --git a/src/burp/ui/About.java b/src/burp/ui/About.java index 35ea661..7baa79c 100644 --- a/src/burp/ui/About.java +++ b/src/burp/ui/About.java @@ -4,6 +4,8 @@ package burp.ui; +import burp.Config; + import java.awt.*; import javax.swing.*; @@ -29,23 +31,20 @@ private void initComponents() { //======== scrollPane1 ======== { + + //---- textArea1 ---- + textArea1.setLineWrap(true); scrollPane1.setViewportView(textArea1); } add(scrollPane1, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); // JFormDesigner - End of component initialization //GEN-END:initComponents - textArea1.setText(about); + textArea1.setText(Config.ABOUT); } // JFormDesigner - Variables declaration - DO NOT MODIFY //GEN-BEGIN:variables private JScrollPane scrollPane1; private JTextArea textArea1; // JFormDesigner - End of variables declaration //GEN-END:variables - private String about = "Author:0chen(@0chencc)\n" + - "Twitter:@0chencc\n" + - "GitHub:https://github.com/0Chencc\n" + - "Wechat Official Accounts(公众号):XizhouPoetry\n" + - "Repository Url:https://github.com/0Chencc/CTFCrackTools\n" + - "米斯特安全团队招CTF选手,有意向联系admin@hi-ourlife.com"; } diff --git a/src/burp/ui/DecodePanel.java b/src/burp/ui/DecodePanel.java index f2ad3f5..4d4a5f4 100644 --- a/src/burp/ui/DecodePanel.java +++ b/src/burp/ui/DecodePanel.java @@ -2,9 +2,10 @@ * Created by JFormDesigner on Thu Nov 25 10:28:49 CST 2021 */ -import burp.fuction.CoreFunc; -import burp.fuction.PythonFunc; -import burp.json.PluginsJson; +import burp.Config; +import ctfcracktools.fuction.CodeMode; +import org.ctfcracktools.fuction.CoreFunc; +import org.ctfcracktools.json.PluginsJson; import java.awt.*; import java.awt.event.*; @@ -37,7 +38,7 @@ private void pluginsComboBoxActionPerformed(ActionEvent e) { return; } String select = pluginsComboBox.getItemAt(pluginsComboBox.getSelectedIndex()); - PythonFunc pyFunc = new PythonFunc(); + Map plugin = json.search(select); String[] prams = {}; ArrayList keys = new ArrayList<>(); @@ -45,15 +46,15 @@ private void pluginsComboBoxActionPerformed(ActionEvent e) { keys = (ArrayList) plugin.get("key"); prams = new String[keys.size()+1]; } - pyFunc.loadFile(plugin.get("path").toString()); + Config.pyFunc.loadFile(plugin.get("path").toString()); if (keys.size()>=1){ prams[0] = inputArea.getText(); for (int i = 1;i plugin = pyFunc.getAuthorInfo(pluginPath); + Map plugin = Config.pyFunc.getAuthorInfo(pluginPath); plugin.put("path",pluginPath); plugins.add(plugin); json.writeJson(plugins); diff --git a/src/burp/ui/SettingConfig.java b/src/burp/ui/SettingConfig.java index 016fb79..a7745c7 100644 --- a/src/burp/ui/SettingConfig.java +++ b/src/burp/ui/SettingConfig.java @@ -4,13 +4,15 @@ package burp.ui; +import burp.json.SettingJson; +import burp.json.SettingJson; + import java.awt.*; import java.awt.event.*; import java.util.Map; import javax.swing.*; import javax.swing.filechooser.FileNameExtensionFilter; -import burp.json.SettingJson; /** * @author 0chencc