This is a collection of commands that I've found helpful, and a lot of times end up reusing (and trying to find them again in some of these cases as well). I'll continue to add to this list, and feel free to provide any suggestions or additions.
sed -e 's/$/<text to insert here>/' -i <filename>.txt
tar -xvf <filename>
echo '<text to insert here>' >> <filename>
<command> >out 2>&1
sudo apt-get update -y && sudo apt-get dist-upgrade -y
tree -L 1 | tail 1
grep -E "item1.*item2" .
# format: if( condition, value_if_true, value_if_false)
WHERE if(<field_name> = '<field value>','true','false')
SELECT <field_name> , count(*) AS <count_field_name>
SHOW PARTITIONS <table>
TBLPROPERTIES
(
"skip.header.line.count"="1"
)
SELECT * FROM "database"."table"
WHERE value IN ('unique_value1','unique_value2')
netstat -l
%27 = '
%22 = "
%3C = <
%3E = >
%2F = /
%3F = ?
%00 = NULL
%20 = space
%26 = &
Example of " && "
%20%26%26%20
echo 'text' >> file
sed -i "1iTEXTHERE" file
# In bash:
echo <base 64 coded string here> | base64 -d
grep -rnw . -e "<pattern>"
# Starting a screen:
screen -S my_screen_session_name
# List running screens:
screen -ls
# Return to running screen (if only one is running):
screen -r
# If multiple are running:
screen -r my_screen_session_name
screen -dmS <name> sh -c "<command>; exec bash"
grep -i <texthere> *
# Configuring Git User
git config --global user.name <user>
# Clone a Git Repo
git clone <url>
eval "$(ssh-agent -s)"
final_list = (list(set(first_list) - set(second_list)))
git pull origin <new_branch>
git fetch origin <new_branch>
git checkout <new_branch>
sudo -V
cat /usr/share/nmap/scripts/script.db
# Add line number to awk command
awk '{print NR,$0} file.txt
if [ ! -f /home/user ]; then
mkdir /home/user
fi
if [ ! -f /home/user/test.txt ]; then
touch /home/user/test.txt
fi
export -p
1 && 2 - runs 2 if 1 is successful
1 ; 2 - runs 1 then 2 (doesn't matter if successful)
1 || 2 - runs 2 if 1 fails
1 | 2 - runs 1 then pipes output to 2
# The "{} \;" operators at the end of the command are required. Example:
find / -name <filename> -exec grep <string> {} \;
# Do a search that starts with the string that you are looking for with '^<string>'. Example:
find / -name <filename> -exec grep '^<string>' {} \;
# Check file location using find and grep with -H. Example:
find / -name <filename> -exec grep -H <string> {} \;
# Check lines within a file with -A <number>. Example:
find / -name <filename> -exec grep -A 3 <string> {} \;
# Tar Switches
# -x: Extract files from an archive.
# -z: uses the compress program when operating on files
# -v: Verbose
# -f: use file within the command
# Tar Examples
tar -xzvf <file>.tgz
import logging
import os
import json
import boto3
import time
import datetime
from botocore.exceptions import ClientError
logger = logging.getLogger()
logger.setLevel(logging.INFO)
current_date = datetime.datetime.now()
current_date_string = str(current_date)
aws s3 ls %s --recursive | tail -n +1 | head -1" % file_name
git pull
# List current branches after pull
git branch
# Switch to branch
git checkout new branch
# Commit and comment your code
git commit -m "comment here"
# Push your code
git push
git branch -d <branch_name>
OR
git fetch -p
git push --delete origin <tag_name>
git fetch --tags -f
cat <file_name> | python -m json.tool > <new_file_name>
jq --raw-output '.field,.sub_field'
jq --slurp '.' *
Windows: Ctrl + /
Mac: Command + /
Mac: Ctrl + A to select all lines, Shift + Alt + I (Windows) or Shift + Option + I to put cursor at end of all lines, Home key to go to beginning of each line
sudo code --user-data-dir="." --no-sandbox
parser.add_argument('--fake-option', action='store_true')
select = parser.parse_args()
if select.fake-option:
dostuff()
virtualenv --python=python3 venv
source venv/bin/activate
# Install virtualenv
pip install virtualenv (might need sudo)
# Create virtual environment
virtualenv venv
# Activate virtual environment
source venv/bin/activate
# Deactivate virtual environment
deactivate
:w - write to file
:q - quit file
x - deletes characters
u - undo change
dd - deletes entire line
p - paste
yy - copy current line
5yy - copy 5 current lines
J - join the next line
f - find character within a line
/ - find word within file
:%s - substitute words within the document (example: :%s/Word/word/gc) g = global, replaces each string within the file, c = confirmation
:n - move to next file
:N - move to previous file
:e - add second file to edit
:buffer - switch files
:wq - save and quit
:wq! - save and quit (without prompt)
:q! - quit without saving
$ - go to the end of a line
sudo apt update
sudo apt install apache2 -y
service apache2 start
if 'JSONKey' in json:
variable = json['JSONKey']
print(variable)
- Credit to HackerOne: https://www.hackerone.com/blog-How-To-Server-Side-Request-Forgery-SSRF
# Create a Ruby file for running a vulnerable server
vim vuln-server.rb
# Add the following content to the file:
require 'sinatra'
require 'open-uri'
set :bind, '0.0.0.0'
set :port, 80
get '/' do
format 'RESPONSE: %s', open(params[:url]).read
end
# Install Sinatra using Ruby
gem install sinatra
# Run the server in the background
ruby vuln-server.rb
# Code to print out info within the terminal
logFormatter = '%(asctime)s - %(levelname)s - %(message)s'
logging.basicConfig(format=logFormatter, level=logging.INFO)
# Code to set the logger up
logger = logging.getLogger()
logger.setLevel(logging.INFO)
# Code to set up the logging file locally for review
output_handle = logging.FileHandler('loggertest.log')
output_handle.setLevel(logging.INFO)
logger.addHandler(output_handle)
# Code to set up the logging format for logs within the logging file
formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s')
output_handle.setFormatter(formatter)
# Code for the handler needed for inputting the logs into the logging file
logger.addHandler(output_handle)
logger.info("Logs are contained in loggertest.log")
original_print = print
def timestamp(*args, **kwargs):
original_print(datetime.datetime.now(), *args, **kwargs)
print = timestamp
export PS1='> '
# Normal Mode
echo Red or Blue?
read color
echo $color
# Silent Mode
echo Green or Yellow?
read -s color
echo $color
grep --number file.txt
OR
grep -n file.txt
cat file.txt | grep "cool phrase" | wc -l
pkill -f <process_name>
<a href="url">linkhere</a>
import string
import random
letters = string.ascii_letters
numbers = string.digits
special_chars = string.punctuation
dummy_phrase = (''.join(random.choice(letters + numbers + special_chars) for char in range(24)))
dummy_string = dummy_phrase.replace('@','').replace('/','').replace('"','')
print(dummy_string)
dupe_list = ['A', 'B', 'A']
clean_list = []
for letter in dupe_list:
if letter not in clean_list:
clean_list.append(letter)
# Scale down to the array to parse
CoreValueList: list = []
array_parse = payload['Array']
# Create a for loop to look for the value you need, and return value based on your logic
for core_value in array_parse:
print(core_value)
if (core_value['Array_Value'] == 'foo'):
CoreValueList.append(core_value)
# Simple Class
class CamelCaseName:
"""Docstring for class"""
value = "One"
# How to call class values
def call_class_values:
"""Function to call class values"""
number = CamelCaseName.value # Retrieves value within the class above
print(number)
# How to call class doc string
print(CamelCaseName.__doc__)
# Check current symbolic link
ls -l /usr/bin/python
# Update symbolic link (example uses updating to 3.8)
rm /usr/bin/python (or python3)
ln -s /usr/bin/python3.8 /usr/bin/python (or python3)
input_value_raw = input("Enter a value: ")
print(type(input_value))
input_value = str(input_value_raw)
# Convert dict to string
dict_value = {'key1': 'value1', 'key2': 'value2'}
dict_value_string = str(dict_value)
print(type(dict_value_string))
# Convert string to dict
dict_value_string = "{'key1': 'value1', 'key2': 'value2'}"
dict_value = eval(dict_value_string)
print(type(dict_value))
# Create a list
list_value = ['value1', 'value2', 'value3']
# Create an if statement
if 'value1' in list_value:
print('value1 is in the list')
package main
import (
"fmt"
)
package main
import (
"fmt"
)
func testing() {
fmt.Println("Hello World")
}
func main() {
testing() // Call the testing function above.
}
test_var := "Hello" // Defines a variable and adds the type based on intelligence
var greeting string = "Hello" // Defines a variable and adds it specifically
fmt.Println(test_var) // Prints the variable
fmt.Println(greeting) // Prints the variable
func if_testing() {
fmt.Println("Let's try an if statement. Say something.")
var if_input string
fmt.Scanln(&if_input)
if if_input == "something" {
fmt.Println("You said something.")
os.Exit(0)
} else if if_input == "nothing" {
fmt.Println("You said nothing.")
os.Exit(0)
} else if if_input == "random" {
fmt.Println("You said", if_input)
os.Exit(0)
} else {
fmt.Println("You said something else.")
}
}
func ec2_test() {
// Standard session declaration for using AWS SDK for Go v1
session := session.Must(session.NewSessionWithOptions(session.Options{
SharedConfigState: session.SharedConfigEnable,
}))
ec2_client := ec2.New(session) // Using the standard session declaration
output, err := ec2_client.DescribeInstances(nil)
if err != nil {
log.Fatal(err)
}
fmt.Println("Let's describe some instances.")
// fmt.Println(output)
for _, reserv := range output.Reservations { //This is how you parse the JSON content initially.
fmt.Println(reserv) // You can print out the variable here.
fmt.Println(reserv.Instances) // For subfields, you can use this format.
for _, bdm := range reserv.Instances { // Can print out nested here as well.
fmt.Println(bdm.BlockDeviceMappings)
}
}
}
GOOS=windows GOARCH=amd64 go build -o go_code.exe go_code.go
// AND
if a && b {
fmt.Println("Both a and b are true")
}
// OR
if a || b {
fmt.Println("One of a and b is true")
}
// NOT
if !a {
fmt.Println("a is false")
}
# Initialize repo to add go.mod
go init <file name with modules>
# Use tidy to load the modules
go mod tidy
taskkill /F /IM "taskname.exe"
# Install virtualenv
pip install virtualenv
# OR
pip3 install virtualenv
# Then
python3 -m venv env # This may not work, try skipping this step
# Create virtual environment
virtualenv -p python3 <envname> # Name the environment whatever you want
# Active the env environment
source <envname>/bin/activate
if a == 1 && b == 2 {
fmt.Println("Both a and b are true")
}
# OR
if (a == 1 and b ==2):
fmt.Println("Both a and b are true")
user = "John"
print("Hello {name}".format(name=user))
resource "aws_instance" "testing" {
ami = "<dummy_ami>"
instance_type = "t2.micro"
subnet_id = "<dummy_subnet_id>" # Required field if the default VPC is not being used.
terraform -chdir=<path_to_deploy_from> apply
# OPA Policy Evaluation Command
./opa eval --format pretty -i <stack_file_name>.json -d <rego_file_name>.rego "data"
# Query to get the value of allow:
./opa eval --format pretty -i <stack_file_name>.json -d <rego_file_name>.rego "data" | jq --raw-output '.opa_policies.allow' > allow.txt
# Stash changes to a branch
git stash
# Unstash changes to a branch
git stash pop
# From checked out branch (or feature branch)
git rebase <main branch>
# To update settings for git config rebasing
git config rebase.true
# Reference: git-scm.com/docs/git-rebase
# Remove the last commit
git reset --hard HEAD~1
git push --force
# Remove a specific commit
git reset --hard <commit_hash>
git push --force
yarn install --mode update-lockfile
# Open tmux
tmux
# Begin session with specific name
tmux new -s <session_name>
# Kill tmux session
tmux kill-session -t <session_number>
grep <word> * -i
ln -s <file> <link>
# Connect to a Redis server
redis-cli -h <hostname>
Redis commands (Link: https://redis.io/docs/latest/commands/)
# Select a database
> select
#Look at information and statistics of a Redis server (when connected)
> info
# List all available keys
> KEYS *
# Get value of key
> get <key value name> (can't use the number of the key here)