Skip to content

Commit 4ad2831

Browse files
committed
bump v0.3.0
0 parents  commit 4ad2831

1,081 files changed

Lines changed: 230583 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.cargo/config.toml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
[build]
2+
jobs=8
3+
4+
5+
[target.x86_64-pc-windows-gnu]
6+
rustflags = [
7+
"-C", "link-arg=-s",
8+
"-C", "link-arg=-Wl,--gc-sections",
9+
]
10+
11+
[target.x86_64-pc-windows-msvc]
12+
rustflags = [
13+
"-C","link-arg=/DEBUG:NONE",
14+
"-C", "target-feature=+crt-static",
15+
]
16+
17+
[target.i686-pc-windows-msvc]
18+
rustflags = [
19+
"-C", "link-args=/SUBSYSTEM:CONSOLE,5.01",
20+
]
21+
22+
[target.'cfg(target_os = "macos")']
23+
rustflags = [
24+
"-C", "link-arg=-dead_strip"
25+
]
26+
27+
[target.'cfg(target_os = "linux")']
28+
rustflags = [
29+
"-C", "link-arg=-Wl,--gc-sections",
30+
"-C", "link-arg=-Wl,--strip-all",
31+
]
32+
33+
# [target.'cfg(target_os = "windows")']
34+
# rustflags = [
35+
# "-C", "target-feature=+crt-static",
36+
# ]

.github/workflows/check.yaml

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
name: check
2+
3+
on:
4+
push:
5+
branches: [main, master]
6+
pull_request:
7+
branches: [main, master]
8+
workflow_dispatch:
9+
inputs:
10+
target:
11+
description: '指定 target(留空跑全部)'
12+
required: false
13+
default: ''
14+
phase:
15+
description: 'check / feature / test / mutant / profile / all'
16+
required: false
17+
default: 'all'
18+
toolchain:
19+
description: 'Rust toolchain (e.g. nightly-2024-09-18)'
20+
required: false
21+
default: 'nightly-2024-09-18'
22+
23+
permissions:
24+
contents: read
25+
26+
jobs:
27+
check-linux:
28+
runs-on: ubuntu-latest
29+
strategy:
30+
fail-fast: false
31+
matrix:
32+
target:
33+
- x86_64-unknown-linux-musl
34+
- x86_64-pc-windows-gnu
35+
steps:
36+
- name: Checkout
37+
uses: actions/checkout@v4
38+
with:
39+
submodules: recursive
40+
token: ${{ secrets.GH_PAT }}
41+
42+
- name: Install Rust toolchain
43+
uses: dtolnay/rust-toolchain@master
44+
with:
45+
toolchain: ${{ github.event.inputs.toolchain || 'nightly-2024-09-18' }}
46+
targets: ${{ matrix.target }}
47+
48+
- name: Install cross-compilation tools
49+
run: |
50+
sudo apt-get update
51+
sudo apt-get install -y gcc-mingw-w64-x86-64 musl-tools protobuf-compiler
52+
sudo ln -sf /usr/bin/musl-gcc /usr/local/bin/x86_64-linux-musl-gcc
53+
54+
- name: Rust cache
55+
uses: Swatinem/rust-cache@v2
56+
with:
57+
shared-key: "check-${{ matrix.target }}"
58+
cache-targets: true
59+
cache-all-crates: true
60+
save-if: ${{ github.event_name == 'push' || github.event_name == 'workflow_dispatch' }}
61+
62+
- name: Fix line endings
63+
run: |
64+
sudo apt-get install -y dos2unix 2>/dev/null || true
65+
find scripts/check -name '*.sh' -exec dos2unix {} + 2>/dev/null || \
66+
find scripts/check -name '*.sh' -exec sed -i 's/\r$//' {} +
67+
68+
- name: Determine phase
69+
id: phase
70+
run: |
71+
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
72+
echo "value=${{ github.event.inputs.phase || 'all' }}" >> $GITHUB_OUTPUT
73+
else
74+
echo "value=test" >> $GITHUB_OUTPUT
75+
fi
76+
77+
- name: Run checks
78+
run: |
79+
chmod +x scripts/check/check.sh scripts/check/profile.sh
80+
./scripts/check/check.sh --target ${{ matrix.target }} --phase ${{ steps.phase.outputs.value }} --ci
81+
82+
check-darwin:
83+
runs-on: macos-latest
84+
steps:
85+
- name: Checkout
86+
uses: actions/checkout@v4
87+
with:
88+
submodules: recursive
89+
token: ${{ secrets.GH_PAT }}
90+
91+
- name: Install protobuf
92+
run: brew install protobuf
93+
94+
- name: Install Rust toolchain
95+
uses: dtolnay/rust-toolchain@master
96+
with:
97+
toolchain: ${{ github.event.inputs.toolchain || 'nightly-2024-09-18' }}
98+
99+
- name: Rust cache
100+
uses: Swatinem/rust-cache@v2
101+
with:
102+
shared-key: "check-aarch64-apple-darwin"
103+
cache-targets: true
104+
cache-all-crates: true
105+
save-if: ${{ github.event_name == 'push' || github.event_name == 'workflow_dispatch' }}
106+
107+
- name: Fix line endings
108+
run: |
109+
find scripts/check -name '*.sh' -exec sed -i '' 's/\r$//' {} +
110+
111+
- name: Determine phase
112+
id: phase
113+
run: |
114+
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
115+
echo "value=${{ github.event.inputs.phase || 'all' }}" >> $GITHUB_OUTPUT
116+
else
117+
echo "value=test" >> $GITHUB_OUTPUT
118+
fi
119+
120+
- name: Run checks
121+
run: |
122+
chmod +x scripts/check/check.sh scripts/check/profile.sh
123+
./scripts/check/check.sh --target aarch64-apple-darwin --phase ${{ steps.phase.outputs.value }} --ci

.github/workflows/generate.yaml

Lines changed: 233 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,233 @@
1+
name: generate malefic
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
remark:
7+
description: 'You can write something here, it will appear in the TITLE of `gh run list`, and help u find the artifact easily.'
8+
required: false
9+
default: ''
10+
release:
11+
description: 'Release version (default: none, if you want to upload to a GitHub Release, create a release and provide the version).'
12+
required: false
13+
default: "none"
14+
targets:
15+
description: 'Target to compile (comma separated, e.g., windows-x64-gnu,windows-x32-gnu)'
16+
required: true
17+
edition:
18+
description: 'Edition'
19+
required: false
20+
default: 'community'
21+
package:
22+
description: 'Package'
23+
required: true
24+
default: 'beacon'
25+
malefic_modules_features:
26+
description: 'Malefic modules features'
27+
required: false
28+
default: 'full'
29+
malefic_config_yaml:
30+
description: 'Malefic config (Base64-encoded content of implant.yaml , will be masked in logs)'
31+
required: false
32+
autorun_yaml:
33+
description: 'Autorun config (Base64-encoded content of prelude.yaml , will be masked in logs)'
34+
required: false
35+
36+
run-name: ${{ github.event.inputs.remark }}
37+
38+
permissions:
39+
contents: write
40+
41+
jobs:
42+
set_targets:
43+
runs-on: ubuntu-22.04
44+
outputs:
45+
targets_json: ${{ steps.set_targets.outputs.targets_json }}
46+
steps:
47+
- name: Set matrix
48+
id: set_targets
49+
run: |
50+
TARGETS="${{ github.event.inputs.targets }}"
51+
TARGETS_JSON=$(echo "[\"${TARGETS//,/\",\"}\"]")
52+
echo "targets_json=$TARGETS_JSON" >> $GITHUB_OUTPUT
53+
54+
generate:
55+
needs: set_targets
56+
runs-on: ubuntu-22.04
57+
strategy:
58+
matrix:
59+
target: ${{ fromJson(needs.set_targets.outputs.targets_json) }}
60+
steps:
61+
- name: Checkout code
62+
uses: actions/checkout@v4
63+
with:
64+
token: ${{ secrets.GH_PAT }}
65+
submodules: recursive
66+
fetch-depth: 0
67+
68+
- name: Judge platform and arch
69+
run: |
70+
if [[ "${{matrix.target}}" == *"windows"* ]]; then
71+
echo "platform=win" >> $GITHUB_ENV
72+
elif [[ "${{matrix.target}}" == *"linux"* ]]; then
73+
echo "platform=linux" >> $GITHUB_ENV
74+
elif [[ "${{matrix.target}}" == *"darwin"* ]]; then
75+
echo "platform=darwin" >> $GITHUB_ENV
76+
fi
77+
78+
if [[ "${{matrix.target}}" == *"x86_64"* ]]; then
79+
echo "arch=x64" >> $GITHUB_ENV
80+
else
81+
echo "arch=x86" >> $GITHUB_ENV
82+
fi
83+
84+
- name: Setup resources
85+
run: |
86+
# Community edition: resources (prebuild .a/.lib) are already in the repository
87+
ls resources/
88+
89+
- name: Generate cache key
90+
id: mutant_cache_key
91+
run: |
92+
HASH=$(find malefic-mutant -name "*.rs" -o -name "Cargo.toml" -o -name "Cargo.lock" | sort | xargs cat | sha256sum | cut -d' ' -f1)
93+
echo "key=mutant-$HASH" >> $GITHUB_OUTPUT
94+
95+
- name: Cache malefic-mutant binary
96+
id: cache_mutant
97+
uses: actions/cache@v4
98+
with:
99+
path: |
100+
target/x86_64-unknown-linux-musl/release/malefic-mutant
101+
key: ${{ steps.mutant_cache_key.outputs.key }}
102+
103+
- name: Pull Docker image
104+
run: |
105+
docker pull ghcr.io/chainreactors/malefic-builder:latest
106+
107+
- name: Build malefic-mutant
108+
if: steps.cache_mutant.outputs.cache-hit != 'true'
109+
run: |
110+
docker run -v $(pwd):/root/src ghcr.io/chainreactors/malefic-builder:latest \
111+
bash -c "cargo build -p malefic-mutant --release --target x86_64-unknown-linux-musl"
112+
113+
- name: Setup malefic-mutant
114+
run: |
115+
mkdir -p target/x86_64-unknown-linux-musl/release/
116+
cp target/x86_64-unknown-linux-musl/release/malefic-mutant malefic-mutant-x86_64-unknown-linux-musl
117+
chmod +x malefic-mutant-x86_64-unknown-linux-musl
118+
119+
- name: Generate implant.yaml
120+
if : ${{ github.event.inputs.malefic_config_yaml != null }}
121+
run: |
122+
SECRET_CONFIG_YAML_CONTENT=$(jq -r '.inputs.malefic_config_yaml' $GITHUB_EVENT_PATH)
123+
echo "::add-mask::$SECRET_CONFIG_YAML_CONTENT"
124+
echo $SECRET_CONFIG_YAML_CONTENT
125+
echo "SECRET_CONFIG_YAML_CONTENT=$SECRET_CONFIG_YAML_CONTENT" >> $GITHUB_ENV
126+
echo "$SECRET_CONFIG_YAML_CONTENT" | base64 -d > config.yaml
127+
128+
- name: Generate prelude.yaml
129+
if : ${{ github.event.inputs.autorun_yaml != null }}
130+
run: |
131+
SECRET_AUTORUN_YAML_CONTENT=$(jq -r '.inputs.autorun_yaml' $GITHUB_EVENT_PATH)
132+
echo "::add-mask::$SECRET_AUTORUN_YAML_CONTENT"
133+
echo "SECRET_AUTORUN_YAML_CONTENT=$SECRET_AUTORUN_YAML_CONTENT" >> $GITHUB_ENV
134+
echo "$SECRET_AUTORUN_YAML_CONTENT" | base64 -d > autorun.yaml
135+
136+
- name: Setup Cargo cache directories
137+
run: |
138+
mkdir -p ~/.cargo/registry
139+
mkdir -p ~/.cargo/git
140+
mkdir -p ./cargo-cache/registry
141+
mkdir -p ./cargo-cache/git
142+
143+
- name: Cache Rust dependencies
144+
id: cache_rust
145+
uses: actions/cache@v4
146+
with:
147+
path: |
148+
./cargo-cache/registry
149+
./cargo-cache/git
150+
target
151+
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}-${{ matrix.target }}-${{ github.event.inputs.package }}
152+
restore-keys: |
153+
${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}-${{ matrix.target }}-
154+
${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}-
155+
${{ runner.os }}-cargo-
156+
157+
- name: Verify cache restore
158+
run: |
159+
echo "Cache hit: ${{ steps.cache_rust.outputs.cache-hit }}"
160+
echo "Checking cargo cache directories:"
161+
ls -la ./cargo-cache/ || echo "cargo-cache directory not found"
162+
ls -la ./cargo-cache/registry/ || echo "registry directory not found"
163+
ls -la ./cargo-cache/git/ || echo "git directory not found"
164+
165+
- name: Build(${{ github.event.inputs.package }}, ${{matrix.target}})
166+
if : ${{ github.event.inputs.package == 'beacon' }}
167+
shell: 'script --return --quiet --log-out /dev/null --command "bash -e {0}"'
168+
run: |
169+
docker run -v $(pwd):/root/src -v $(pwd)/cargo-cache/registry:/root/cargo/registry -v $(pwd)/cargo-cache/git:/root/cargo/git ghcr.io/chainreactors/malefic-builder:latest \
170+
bash -c "./malefic-mutant-x86_64-unknown-linux-musl generate beacon && ./malefic-mutant-x86_64-unknown-linux-musl build malefic --target ${{matrix.target}}"
171+
172+
- name: Build(${{ github.event.inputs.package }}, ${{matrix.target}})
173+
if : ${{ github.event.inputs.package == 'pulse' }}
174+
shell: 'script --return --quiet --log-out /dev/null --command "bash -e {0}"'
175+
run: |
176+
docker run -v $(pwd):/root/src -v $(pwd)/cargo-cache/registry:/root/cargo/registry -v $(pwd)/cargo-cache/git:/root/cargo/git ghcr.io/chainreactors/malefic-builder:latest \
177+
bash -c "./malefic-mutant-x86_64-unknown-linux-musl generate pulse -p $platform -a $arch && ./malefic-mutant-x86_64-unknown-linux-musl build pulse --target ${{matrix.target}}"
178+
179+
- name: Build(${{ github.event.inputs.package }}, ${{matrix.target}})
180+
if : ${{ github.event.inputs.package == 'bind' }}
181+
shell: 'script --return --quiet --log-out /dev/null --command "bash -e {0}"'
182+
run: |
183+
docker run -v $(pwd):/root/src -v $(pwd)/cargo-cache/registry:/root/cargo/registry -v $(pwd)/cargo-cache/git:/root/cargo/git ghcr.io/chainreactors/malefic-builder:latest \
184+
bash -c "./malefic-mutant-x86_64-unknown-linux-musl generate bind && ./malefic-mutant-x86_64-unknown-linux-musl build bind --target ${{matrix.target}}"
185+
186+
- name: Build(${{ github.event.inputs.package }}, ${{matrix.target}})
187+
if : ${{ github.event.inputs.package == 'prelude' }}
188+
shell: 'script --return --quiet --log-out /dev/null --command "bash -e {0}"'
189+
run: |
190+
docker run -v $(pwd):/root/src -v $(pwd)/cargo-cache/registry:/root/cargo/registry -v $(pwd)/cargo-cache/git:/root/cargo/git ghcr.io/chainreactors/malefic-builder:latest \
191+
bash -c "./malefic-mutant-x86_64-unknown-linux-musl generate prelude autorun.yaml && ./malefic-mutant-x86_64-unknown-linux-musl build prelude --target ${{matrix.target}}"
192+
193+
- name: Build(${{ github.event.inputs.package }},${{matrix.target}})
194+
if : ${{ github.event.inputs.package == '3rd' }}
195+
shell: 'script --return --quiet --log-out /dev/null --command "bash -e {0}"'
196+
run: |
197+
docker run -v $(pwd):/root/src -v $(pwd)/cargo-cache/registry:/root/cargo/registry -v $(pwd)/cargo-cache/git:/root/cargo/git ghcr.io/chainreactors/malefic-builder:latest \
198+
bash -c "./malefic-mutant-x86_64-unknown-linux-musl generate modules -m full && ./malefic-mutant-x86_64-unknown-linux-musl build 3rd -m ${{ github.event.inputs.malefic_modules_features }} --target ${{matrix.target}}"
199+
200+
- name: Build(${{ github.event.inputs.package }},${{matrix.target}})
201+
if : ${{ github.event.inputs.package == 'modules' }}
202+
shell: 'script --return --quiet --log-out /dev/null --command "bash -e {0}"'
203+
run: |
204+
docker run -v $(pwd):/root/src -v $(pwd)/cargo-cache/registry:/root/cargo/registry -v $(pwd)/cargo-cache/git:/root/cargo/git ghcr.io/chainreactors/malefic-builder:latest \
205+
bash -c "./malefic-mutant-x86_64-unknown-linux-musl generate modules -m ${{ github.event.inputs.malefic_modules_features }} && ./malefic-mutant-x86_64-unknown-linux-musl build modules -m ${{ github.event.inputs.malefic_modules_features }} --target ${{matrix.target}}"
206+
207+
- name: Move ${{ github.event.inputs.package }} to output
208+
run: |
209+
mkdir -p output
210+
sudo chmod -R 777 target
211+
sudo chmod -R 777 output
212+
export prefix=./target/${{matrix.target}}/release
213+
export suffix=$([ "$platform" = "win" ] && echo ".exe" || echo "")
214+
tree ./target
215+
if ${{ github.event.inputs.package == 'beacon' }} || ${{ github.event.inputs.package == 'bind' }}; then \
216+
mv $prefix/malefic$suffix output/malefic-${{ github.event.inputs.package }}$suffix; \
217+
elif ${{ github.event.inputs.package == 'prelude' }}; then \
218+
mv $prefix/malefic-prelude$suffix output/malefic-prelude$suffix; \
219+
elif ${{ github.event.inputs.package == 'pulse' }}; then \
220+
mv $prefix/malefic-pulse$suffix output/malefic-pulse$suffix;
221+
elif ${{ github.event.inputs.package == 'modules' }}; then \
222+
mv $prefix/malefic_modules.dll output/malefic_modules-${{matrix.target}}.dll; \
223+
elif ${{ github.event.inputs.package == '3rd' }}; then \
224+
mv $prefix/malefic_3rd.dll output/malefic_3rd-${{matrix.target}}.dll; \
225+
fi
226+
227+
- name: Upload artifact ${{matrix.target}}
228+
if: ${{ github.event.inputs.release == 'none' }}
229+
uses: actions/upload-artifact@v4
230+
with:
231+
name: malefic-${{matrix.target}}-${{ github.run_id }}
232+
path: output/*
233+
retention-days: 2 # you can change this value

0 commit comments

Comments
 (0)