Skip to content

Commit

Permalink
优化 Decoder ;新增 hex 编/解码
Browse files Browse the repository at this point in the history
  • Loading branch information
yhy0 committed May 10, 2023
1 parent aa3420d commit 5a14012
Show file tree
Hide file tree
Showing 6 changed files with 147 additions and 13 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ https://infosecwriteups.com/403-bypass-lyncdiscover-microsoft-com-db2778458c33
- Intruder 模块 手动修改request包内容时,每写一个字符,要重新点击鼠标,将光标重新定位到要修改的位置

- Attack 显示不能切换别的 Intruder tab页,不然结果就不显示了,前端数据绑定问题,太菜了,还没想好怎么写

## License

This code is distributed under the [MIT license](https://github.com/yhy0/ChYing/blob/main/LICENSE). See [LICENSE](https://github.com/yhy0/ChYing/blob/main/LICENSE) in this directory.
Expand Down
4 changes: 4 additions & 0 deletions app.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,10 @@ func (a *App) Decoder(str string, mode string) string {
return decoder.DecodeBase64(str)
case "EncodeBase64":
return decoder.EncodeBase64(str)
case "DecodeHex":
return decoder.DecodeHex(str)
case "EncodeHex":
return decoder.EncodeHex(str)
case "MD5":
return decoder.Md5(str)
default:
Expand Down
121 changes: 111 additions & 10 deletions frontend/src/components/Decoder.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,36 @@
Decode
</n-col>
<n-col span="3">
<n-checkbox @update:checked="handleDecodeUnicode(index)">Unicode</n-checkbox>
<n-checkbox :checked="DecodeUnicode[index]" @update:checked="handleDecodeUnicode(index)">Unicode</n-checkbox>
</n-col>
<n-col span="2">
<n-checkbox @update:checked="handleDecodeURL(index)">URL</n-checkbox>
<n-checkbox :checked="DecodeURL[index]" @update:checked="handleDecodeURL(index)">URL</n-checkbox>
</n-col>
<n-col span="3">
<n-checkbox @update:checked="handleDecodeBase64(index)">Base64</n-checkbox>
<n-checkbox :checked="DecodeBase64[index]" @update:checked="handleDecodeBase64(index)">Base64</n-checkbox>
</n-col>
<n-col span="2">
<n-checkbox @update:checked="handleMD5(index)">MD5</n-checkbox>
<n-checkbox :checked="DecodeHex[index]" @update:checked="handleDecodeHex(index)">Hex</n-checkbox>
</n-col>
<n-col span="2">
<n-checkbox :checked="DecodeMD5[index]" @update:checked="handleMD5(index)">MD5</n-checkbox>
</n-col>
</n-row>
<n-row span="20">
<n-col span="2">
Encode
</n-col>
<n-col span="3">
<n-checkbox @update:checked="handleEncodeUnicode(index)">Unicode</n-checkbox>
<n-checkbox :checked="EncodeUnicode[index]" @update:checked="handleEncodeUnicode(index)">Unicode</n-checkbox>
</n-col>
<n-col span="2">
<n-checkbox @update:checked="handleEncodeURL(index)">URL</n-checkbox>
<n-checkbox :checked="EncodeURL[index]" @update:checked="handleEncodeURL(index)">URL</n-checkbox>
</n-col>
<n-col span="3">
<n-checkbox @update:checked="handleEncodeBase64(index)">Base64</n-checkbox>
<n-checkbox :checked="EncodeBase64[index]" @update:checked="handleEncodeBase64(index)">Base64</n-checkbox>
</n-col>
<n-col span="2">
<n-checkbox :checked="EncodeHex[index]" @update:checked="handleEncodeHex(index)">Hex</n-checkbox>
</n-col>
</n-row>
</n-row>
Expand All @@ -46,59 +52,154 @@
<script setup>
import { ref } from 'vue'
import {Decoder} from '../../wailsjs/go/main/App'
const values = ref([''])
// 这些是为了选中一个,取消其他的选中,更美观
const DecodeUnicode = ref([false])
const DecodeURL = ref([false])
const DecodeBase64 = ref([false])
const DecodeHex = ref([false])
const DecodeMD5 = ref([false])
const EncodeUnicode = ref([false])
const EncodeURL = ref([false])
const EncodeBase64 = ref([false])
const EncodeHex = ref([false])
function addInput(index) {
const lastIndex = values.value.length - 1
const lastValue = values.value[lastIndex]
if (lastValue !== '') {
values.value.push('')
DecodeUnicode.value.push(false)
DecodeURL.value.push(false)
DecodeBase64.value.push(false)
DecodeHex.value.push(false)
DecodeMD5.value.push(false)
EncodeUnicode.value.push(false)
EncodeURL.value.push(false)
EncodeBase64.value.push(false)
EncodeHex.value.push(false)
}
if (index >= 0) {
values.value.splice(index + 2)
DecodeUnicode.value.splice(index + 2)
DecodeURL.value.splice(index + 2)
DecodeBase64.value.splice(index + 2)
DecodeHex.value.splice(index + 2)
DecodeMD5.value.splice(index + 2)
EncodeUnicode.value.splice(index + 2)
EncodeURL.value.splice(index + 2)
EncodeBase64.value.splice(index + 2)
EncodeHex.value.splice(index + 2)
}
}
function handleDecodeUnicode(index) {
function handleDecodeUnicode(index, event) {
DecodeUnicode.value[index] = true
Decoder(values.value[index],"DecodeUnicode").then(result => {
values.value[index+1] = result
})
values.value.splice(index + 2)
clearOtherChecks("DecodeUnicode",index)
}
function handleEncodeUnicode(index) {
EncodeUnicode.value[index] = true
Decoder(values.value[index],"EncodeUnicode").then(result => {
values.value[index+1] = result
})
values.value.splice(index + 2)
clearOtherChecks("EncodeUnicode",index)
}
function handleDecodeURL(index) {
DecodeURL.value[index] = true
Decoder(values.value[index],"DecodeURL").then(result => {
values.value[index+1] = result
})
values.value.splice(index + 2)
clearOtherChecks("DecodeURL",index)
}
function handleEncodeURL(index) {
EncodeURL.value[index] = true
Decoder(values.value[index],"EncodeURL").then(result => {
values.value[index+1] = result
})
values.value.splice(index + 2)
clearOtherChecks("EncodeURL",index)
}
function handleDecodeBase64(index) {
DecodeBase64.value[index] = true
clearOtherChecks("DecodeBase64",index)
Decoder(values.value[index],"DecodeBase64").then(result => {
values.value[index+1] = result
})
values.value.splice(index + 2)
}
function handleEncodeBase64(index) {
EncodeBase64.value[index] = true
clearOtherChecks("EncodeBase64",index)
Decoder(values.value[index],"EncodeBase64").then(result => {
values.value[index+1] = result
})
values.value.splice(index + 2)
}
function handleDecodeHex(index) {
DecodeHex.value[index] = true
clearOtherChecks("DecodeHex",index)
Decoder(values.value[index],"DecodeHex").then(result => {
values.value[index+1] = result
})
values.value.splice(index + 2)
}
function handleEncodeHex(index) {
EncodeHex.value[index] = true
clearOtherChecks("EncodeHex",index)
Decoder(values.value[index],"EncodeHex").then(result => {
values.value[index+1] = result
})
values.value.splice(index + 2)
}
function handleMD5(index) {
DecodeMD5.value[index] = true
clearOtherChecks("DecodeMD5",index)
Decoder(values.value[index],"MD5").then(result => {
values.value[index+1] = result
})
values.value.splice(index + 2)
}
</script>
// 去除其他的选中效果
function clearOtherChecks(exclude, index) {
const checks = [
'DecodeUnicode',
'DecodeURL',
'DecodeBase64',
'DecodeHex',
'EncodeUnicode',
'EncodeURL',
'EncodeBase64',
'EncodeHex',
'DecodeMD5'
]
for (const check of checks) {
if (check !== exclude) {
eval(check + '.value[index] = false')
eval(check + '.value.splice(index + 2)')
}
}
}
</script>

<style scoped>
</style>
6 changes: 4 additions & 2 deletions test/decoder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ import (

func TestDecode(t *testing.T) {
fmt.Println(decoder.DecodeUnicode("\\u0048\\u0065\\u006c\\u006c\\u006f\\u002c\\u0020\\u4e16\\u754c\\u0021"))
fmt.Println(decoder.DecodeURL("Hello%2C+%E4%B8%96%E7%95%8C%21"))
fmt.Println(decoder.DecodeURL("Hello%2C%20%E4%B8%96%E7%95%8C%2B%21"))
fmt.Println(decoder.DecodeBase64("SGVsbG8sIOS4lueVjCE="))
fmt.Println(decoder.DecodeHex("48656c6c6f2c20e4b896e7958c21"))
}

func TestEncode(t *testing.T) {
fmt.Println(decoder.EncodeUnicode("Hello, 世界!"))
fmt.Println(decoder.EncodeURL("Hello, 世界!"))
fmt.Println(decoder.EncodeURL("Hello, 世界+!"))
fmt.Println(decoder.EncodeBase64("Hello, 世界!"))
fmt.Println(decoder.EncodeHex("Hello, 世界!"))
}
15 changes: 15 additions & 0 deletions tools/decoder/decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package decoder

import (
"encoding/base64"
"encoding/hex"
"net/url"
"strconv"
"strings"
Expand Down Expand Up @@ -48,3 +49,17 @@ func DecodeBase64(str string) string {
}
return string(decoded)
}

// DecodeHex hex 解码
func DecodeHex(str string) string {
buf := make([]byte, hex.DecodedLen(len(str)))
n, err := hex.Decode(buf, []byte(str))

if err != nil {
return str
}
if n > 0 {
return string(buf)
}
return str
}
13 changes: 12 additions & 1 deletion tools/decoder/encode.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package decoder

import (
"encoding/base64"
"encoding/hex"
"fmt"
"net/url"
"strings"
)

/**
Expand All @@ -23,10 +25,19 @@ func EncodeUnicode(str string) string {

// EncodeURL URL 编码
func EncodeURL(str string) string {
return url.QueryEscape(str)
encoded := url.QueryEscape(str) // 这个函数会将空格,替换为+
encoded = strings.ReplaceAll(encoded, "+", "%20") // 这里再将+ 替换为 %2B
return encoded
}

// EncodeBase64 Base64 编码
func EncodeBase64(str string) string {
return base64.StdEncoding.EncodeToString([]byte(str))
}

// EncodeHex hex 编码
func EncodeHex(str string) string {
buf := make([]byte, hex.EncodedLen(len(str)))
hex.Encode(buf, []byte(str))
return string(buf)
}

0 comments on commit 5a14012

Please sign in to comment.