Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solved some security issues #54

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 25 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ Ctrl + x + Ctrl + e : launch editor defined by $EDITOR to input your command. Us
Ctrl + z : stop current running process and keep it in background. You can use `fg` to continue the process in the foreground, or `bg` to continue the process in the background.
Ctrl + _ : undo typing.
```

##### Change case
```bash
Esc + u
Expand Down Expand Up @@ -85,7 +86,6 @@ sudo !!
^aaa^bbb^:&
#or
!!:gs/aaa/bbb/

```

##### Run past command that began with (e.g. cat filename)
Expand Down Expand Up @@ -176,12 +176,14 @@ echo "'$foo'"
echo ''$foo''
# bar
```

##### Get the length of variable
```bash
var="some string"
echo ${#var}
# 11
```

##### Get the first character of the variable
```bash
var=string
Expand Down Expand Up @@ -286,15 +288,16 @@ expr 30 \> 20 #1 (true)
```bash
# Number of decimal digit/ significant figure
echo "scale=2;2/3" | bc
#.66

$ .66
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be # instead of $

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above, it is following your style for returned values. where you uses the # as the shell promt indication, usual this would be the $ sign. Should I replace them all for you to the more used $ or would you keep using the #?


# Exponent operator
echo "10^2" | bc
#100
$ 100
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be # instead of $

Copy link
Author

@spirillen spirillen Aug 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By adding a hashtag you would generate a H1 header and not be demonstrating the shell output of the command. And to stick to more common layout for the rest of the document $ should be the right character here

echo "10^2" | bc
$ 100 # returned value from the echo command


# Using variables
echo "var=5;--var"| bc
#4
$ 4
```


Expand All @@ -318,21 +321,25 @@ grep -c "^$"
##### Grep and return only integer
```bash
grep -o '[0-9]*'

#or
grep -oP '\d*'
```
##### Grep integer with certain number of digits (e.g. 3)
```bash
grep '[0-9]\{3\}'

# or
grep -E '[0-9]{3}'

# or
grep -P '\d{3}'
```

##### Grep only IP address
```bash
grep -Eo '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}'

# or
grep -Po '\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}'
```
Expand All @@ -344,6 +351,7 @@ grep -w 'target'
#or using RE
grep '\btarget\b'
```

##### Grep returning lines before and after match (e.g. 'bbo')
```bash
# return also 3 lines after match
Expand Down Expand Up @@ -976,7 +984,7 @@ cat grep_list |xargs -I{} grep {} filename

##### Xargs and sed (replace all old ip address with new ip address under /etc directory)
```bash
grep -rl '192.168.1.111' /etc | xargs sed -i 's/192.168.1.111/192.168.2.111/g'
grep -rl '192.0.2.1' /etc | xargs sed -i 's/192.0.2.1/192.0.2.2/g'
```


Expand Down Expand Up @@ -1249,7 +1257,7 @@ emacs -nw --eval '(org-mode)' --insert <(curl https://raw.githubusercontent.com/

##### Download all from a page
```bash
wget -r -l1 -H -t1 -nd -N -np -A mp3 -e robots=off http://example.com
wget -r -l1 -H -t1 -nd -N -np -A mp3 -e robots=off http://example.net

# -r: recursive and download all links on page
# -l1: only one level link
Expand All @@ -1259,7 +1267,7 @@ wget -r -l1 -H -t1 -nd -N -np -A mp3 -e robots=off http://example.com
# -N: turn on timestamp
# -nd: no parent
# -A: type (separate by ,)
# -e robots=off: ignore the robots.txt file which stop wget from crashing the site, sorry example.com
# -e robots=off: ignore the robots.txt file which stop wget from crashing the site, sorry example.net
```

##### Upload a file to web and download (https://transfer.sh/)
Expand All @@ -1275,7 +1283,7 @@ curl https://transfer.sh/tG8rM/filename.txt -o filename.txt
##### Download file if necessary
```bash
data=file.txt
url=http://www.example.com/$data
url=http://www.example.net/$data
if [ ! -s $data ];then
echo "downloading test data..."
wget $url
Expand All @@ -1284,12 +1292,12 @@ fi

##### Wget to a filename (when a long name)
```bash
wget -O filename "http://example.com"
wget -O filename "http://example.net"
```

##### Wget files to a folder
```bash
wget -P /path/to/directory "http://example.com"
wget -P /path/to/directory "http://example.net"
```

##### Instruct curl to follow any redirect until it reaches the final destination:
Expand Down Expand Up @@ -2444,23 +2452,23 @@ ipmitool -I bmc lan set 1 defgw ipaddr 192.168.0.1

##### Resolve a domain to IP address(es)
```bash
dig +short www.example.com
dig +short www.example.net

# or
host www.example.com
host www.example.net
```

##### Get DNS TXT record a of domain
```bash
dig -t txt www.example.com
dig -t txt www.example.net

# or
host -t txt www.example.com
host -t txt www.example.net
```

##### Send a ping with a limited TTL to 10 (TTL: Time-To-Live, which is the maximum number of hops that a packet can travel across the Internet before it gets discarded.)
```bash
ping 8.8.8.8 -t 10
ping 192.0.2.1 -t 10
Copy link

@dibs dibs Sep 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this packet would travel across the internet but it would with 8.8.8.8

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

by using the RFC:5737 TEST-NET-1 network address 192.0.2.1 you are not promoting any trackers/spyware or any other malicious address. By mention any particular DNS recursor, would only end up in a religious war or mistrust on the idea for this cheat sheet. This is why I changed the bad resolver to a "fictive" address for neutrality.

```

##### Print the route packets trace to network host
Expand Down Expand Up @@ -2527,7 +2535,7 @@ whois example.net

##### Show the SSL certificate of a domain
```bash
openssl s_client -showcerts -connect www.example.com:443
openssl s_client -showcerts -connect www.example.net:443
```

##### Display IP address
Expand Down Expand Up @@ -2577,7 +2585,7 @@ hostnamectl set-hostname "mynode"

##### Find out the web server (e.g Nginx or Apache) of a website
```bash
curl -I http://example.com/
curl -I http://example.net/
# HTTP/1.1 200 OK
# Server: nginx
# Date: Thu, 02 Jan 2020 07:01:07 GMT
Expand Down