Cheatsheet: Difference between revisions

 
(22 intermediate revisions by the same user not shown)
Line 312:
 
= VPN Messages =
<div style="column-count:3;-moz-column-count:3;-webkit-column-count:3">
 
*;Phase 1 - Main Mode
Line 326 ⟶ 325:
ID,Accepted Proposal,DH Key,Nonce,ID Hash
ID Hash
 
*;Phase 2 - Quick Mode
Ph1 Hash,Message ID,Proposal List,Nonce, DH Key,Proxy-ID
Ph1 Hash,Message ID,Accepted Proposal,Nonce,DH Key,Proxy-ID
Ph1 Hash,Message ID,Nonce
</div>
 
 
= HTTP =
Line 380 ⟶ 369:
* Supports OPTIONS, PUT, DELETE, TRACE, CONNECT request methods
<br />
 
;HTTP/1.1 vs HTTP/2
 
* HTTP/2 Supports Page load speed improvements through:
'''Compression of request headers'''
'''Binary protocol'''
'''HTTP/2 Server Push''': capability allows the server to send additional cacheable information to the client that isn’t requested but is anticipated in future requests.
'''Request multiplexing over a single TCP connection'''
'''Request pipelining'''
'''HOL blocking (Head-of-line) — Package blocking'''
 
;HTTP Request Methods
Line 410 ⟶ 409:
 
== HTTP Headers ==
{|class="wikitable"
 
|-
Set-cookie:
! Header !! Uses
Location:
|-
Host:
|Set-cookie ||
Accept
|-
User-Agent
|Location ||1) Used to ask a web browser to load a different web page<br/>Client request:<br/>''GET /index.html HTTP/1.1''<br/>''Host: www.example.com''<br/>Server response:<br/>''HTTP/1.1 302 Found''<br/>''Location: http://www.example.org/index.php.''<br/>
content-type
2) To provide info about location of a newly created resource, the Location header should be sent with an HTTP status code of 201 or 202.
content-length
|-
date
|Host||The host Header tells the webserver which virtual host to use if same virtual host is using several aliases
expires
|-
|Accept||
|-
|User-Agent||
|-
|content-type||
|-
|content-length||
|-
|date||
|-
|expires||
|-
|Authorization||Basic access authentication is used to provide a user name and password when making a request.<br/>Credentials are the base64 encoding of id and password joined by a single colon<br/>Base64-encoding of 'Aladdin:OpenSesame' is 'QWxhZGRpbjpPcGVuU2VzYW1l'<br/>''Authorization: Basic QWxhZGRpbjpPcGVuU2VzYW1l''<br/>''https://Aladdin:OpenSesame@www.example.com/index.html'' ==> This will not ask for the credentials; deprecated now
|-
|Referrer||When a user clicks a hyperlink in a web browser, the browser sends a request to the server holding the destination webpage.<br/>
The request may include the referer field, which indicates the last page the user was on (the one where they clicked the link).
|-
|X-Forwarded-For (XFF)||Used for identifying the originating IP address of a client connecting to a Web Server through an HTTP Proxy or Load Balancer.
|}
 
= FTP =
Line 441 ⟶ 460:
#Client sends the second half of the Diffie-Hellman exchange, Computes the session keys; Switches to encrypted communication
#Server computes the session keys; Switches to encrypted communication.
<br>
 
; SSLv1 vs TLS 1.0 vs TLS1.3
SSL 2.0 - Deprecated
SSL 3.0 - Deprecated
TLS 1.0 - Deprecated
TLS 1.1 - Deprecated
TLS 1.2 -
TLS 1.3 -
 
= NetScaler =
Line 510 ⟶ 538:
[[File:OSFF LSA 2.png|center]]
 
* OSPF path selection: O > O*IA > O*E1 > O*E2 > N1 > N2.
* “area range” summarize type 3 LSA’.
* “summary-address” summarize type 5 & 7 LSA’s.
Line 517 ⟶ 545:
= BGP =
 
* Route Selection Criteria
<div style="column-count:2;-moz-column-count:2;-webkit-column-count:2">
 
*Route Selection Criteria
<center>
{| class="wikitable"
|-
! Attribute !! Which is better !! DirectionType
|-
|Next Hop reachable || Route cannot be used if next hop is unreachable || Well-known Mandatory
|-
|Weight || Bigger; value local to the router; Cisco proprietary; default is 0 for all routes not originated by local router ||
|Weight || Bigger ||
|-
|Local Preference || Bigger; used within AS and exchanged bw iBGP routers; default is 100 || Well-known discretionary
|-
|Locally Injected (Originate) || LocallyPrefer injectedpath islocal betterrouter thanoriginated; Locally injected > iBGP/eBGP learned; In BGP table it will hv next hop 0.0.0.0 ||
|-
|AS Path Length || Smaller; e.g: AS path 1 2 3 is preferred over AS path 1 2 3 4 5 || Well-known Mandatory
|-
|Origin || Prefer IIGP(advertised overby Enetwork &cmd E- overi) Unknown> EGP > INCOMPLETE - '?'(reditributed) || Well-known Mandatory
|-
|MED(Metric) || Smaller; used to advertise to neighbors how they should enter your AS; propagated to all routers within the neighbor AS but not passed along any other AS || Optional non-transitive
|MED || Smaller ||
|-
|Neighbor Type || Prefer eBGP over iBGP ||
|-
|IGP Metric to Next Hop || Smaller; Prefer the path within the AS with the lowest IGP metric to the BGP next hop ||
|-
|Oldest path || Prefer the path that we received first ||
|-
|Router ID || Prefer the path with the lowest BGP neighbor router ID (Manually conf > Highest Loopback IP address > Highest Interface IP address) ||
|-
|Neighbor IP address || Prefer the path with the lowest neighbor IP address ||
|}
<br /center>
<br />
 
Line 558 ⟶ 593:
Notification Always indicate something is wrong
<br />
</div>
 
* Directions
Line 744 ⟶ 778:
== Linux Booting ==
 
#BIOS(Basic Input/Output System) - POST, Loads and executes the MBR boot loader.
 
#MBR (Master Boot Record) - Loads and executes the GRUB boot loader.
Source: [http://technochords.com/linux-booting-process-6-steps/ technochords.com]
#GRUB (Grand Unified Bootloader) - Loads and executes Kernel and Initrd images.
 
#Kernel - Heart of OS; Memory, Process mgmt; Executes INIT process.
The following are the 6 high level stages of a typical Linux boot process:
#Init (initialization) - Decides the Linux run level; default run level to either 3 or 5.
 
#Runlevel programs - Executes programs like sendmail, etc from the run level directory as defined by the run level.
#BIOS
#MBR
#GRUB
#Kernel
#Init
#Runlevel programs
 
;BIOS(Basic Input/Output System) - loads and executes the MBR boot loader.
*Performs some system integrity checks (POST-Power On Self Test)
*Searches, loads, and executes the boot loader program.
*It looks for boot loader in floppy, cd-rom, or hard drive.
*You can press a key (typically F12 of F2, but it depends on your system) during the BIOS startup to change the boot sequence.
*Once the boot loader program is detected and loaded into the memory, BIOS gives the control to it.
 
;MBR (Master Boot Record) - loads and executes the GRUB boot loader.
*It is located in the 1st sector of the bootable disk.
*Typically /dev/hda, or /dev/sda
*MBR is less than 512 bytes in size.
*This has three components:
#primary boot loader info in 1st 446 bytes,
#partition table info in next 64 bytes(16,16,16,16) 4 partitions,
#magic numbers as mbr validation check in last 2 bytes.
*It contains information about GRUB (or LILO in old systems).
 
;GRUB (Grand Unified Bootloader) - loads and executes Kernel and initrd images.
*It is a Multiboot boot loader.
*If you have multiple kernel images installed on your system, you can choose which one to be executed.
*GRUB displays a splash screen, waits for few seconds, if you don’t enter anything, it loads the default kernel image as specified in the grub configuration file.
*GRUB has the knowledge of the filesystem (the older Linux loader LILO didn’t understand filesystem).
*Grub configuration file is /boot/grub/grub.conf (/etc/grub.conf is a link to this).
<pre>
#boot=/dev/sda
default=0
timeout=5
splashimage=(hd0,0)/boot/grub/splash.xpm.gz
hiddenmenu
title CentOS (2.6.18-194.el5PAE)
root (hd0,0)
kernel /boot/vmlinuz-2.6.18-194.el5PAE ro root=LABEL=/
initrd /boot/initrd-2.6.18-194.el5PAE.img
</pre>
*As you notice from the above info, it contains kernel and initrd image.
 
;Kernel
*Once the control is given to kernel which is the central part of all your OS and act as a mediator between hardware and software.
*Kernel once loaded into to RAM it always resides on RAM until the machine is shutdown.
*Once the Kernel starts its operations the first thing it do is executing INIT process.
 
;Init (initialization)
*Looks at the /etc/inittab file to decide the Linux run level.
*Following are the available run levels
0 – halt
1 – Single user mode
2 – Multiuser, without NFS
3 – Full multiuser mode
4 – unused
5 – X11
6 – reboot
 
*Init identifies the default initlevel from /etc/inittab and uses that to load all appropriate program.
*Execute ‘grep initdefault /etc/inittab’ on your system to identify the default run level
*Typically you would set the default run level to either 3 or 5.
 
;Runlevel programs
*When the Linux system is booting up, you might see various services getting started.
*For example, it might say “starting sendmail …. OK”.
*Those are the runlevel programs, executed from the run level directory as defined by your run level.
*Depending on your default init level setting, the system will execute the programs from one of the following directories.
Run level 0 – /etc/rc.d/rc0.d/
Run level 1 – /etc/rc.d/rc1.d/
Run level 2 – /etc/rc.d/rc2.d/
Run level 3 – /etc/rc.d/rc3.d/
Run level 4 – /etc/rc.d/rc4.d/
Run level 5 – /etc/rc.d/rc5.d/
Run level 6 – /etc/rc.d/rc6.d/
 
*Please note that there are also symbolic links available for these directory under /etc directly.
*So, /etc/rc0.d is linked to /etc/rc.d/rc0.d.
*Under the /etc/rc.d/rc*.d/ directories, you would see programs that start with S and K.
#Programs starts with S are used during startup. S for startup.
#Programs starts with K are used during shutdown. K for kill.
#There are numbers right next to S and K in the program names.
#Those are the sequence number in which the programs should be started or killed.
#For example, S12syslog is to start the syslog deamon, which has the sequence number of 12.
#S80sendmail is to start the sendmail daemon, which has the sequence number of 80.
#So, syslog program will be started before sendmail.
 
== Manually Boot using Grub ==
Line 1,000 ⟶ 949:
ls > file.log 2>&1 OR ls &> file.log
ls > file.log 2> /dev/null
 
=== System Calls ===
{{UC}}
 
= Sorting Algorithms =
 
 
'''* Quicksort''' is a good default choice.
It is a good default choice.
It tends to be fast in practice
It tends to be fast in practice with some small tweaks its dreaded O(n2)O(n^2)O(n2) worst-case time complexity becomes very unlikely.
A tried and true favorite.
 
'''Heapsort''' is a good choice if you can't tolerate a worst-case time complexity of O(n2)O(n^2)O(n2) or need low space costs.
* Heapsort
The Linux kernel uses heapsort instead of quicksort for both of those reasons.
'''Merge sort'''It is a good choice if you wantcan't tolerate a stableworst-case sortingtime algorithmcomplexity of O(n2)O(n^2)O(n2) or need low space costs.
The Linux kernel uses heapsort instead of quicksort for both of those reasons.
can easily be extended to handle data sets that can't fit in RAM
 
where the bottleneck cost is reading and writing the input on disk, not comparing and swapping individual items.
* Merge sort
'''Radix sort''' looks fast, with its O(n)O(n)O(n) worst-case time complexity.
It is a good choice if you want a stable sorting algorithm.
if you're using it to sort binary numbers, then there's a hidden constant factor that's usually 32 or 64 (depending on how many bits your numbers are).
It can easily be extended to handle data sets that can't fit in RAM where the bottleneck cost is reading and writing the input on disk, not comparing and swapping individual items.
That's often way bigger than O(lg⁡(n))O(\lg(n))O(lg(n)), meaning radix sort tends to be slow in practice.
 
'''Counting sort''' is a good choice in scenarios where there are small number of distinct values to be sorted.
* Radix sort
This is pretty rare in practice, and counting sort doesn't get much use.
It looks fast, with its O(n)O(n)O(n) worst-case time complexity.
If you're using it to sort binary numbers, then there's a hidden constant factor that's usually 32 or 64 (depending on how many bits your numbers are).
That's often way bigger than O(lg⁡(n))O(\lg(n))O(lg(n)), meaning radix sort tends to be slow in practice.
* Counting sort
It is a good choice in scenarios where there are small number of distinct values to be sorted.
This is pretty rare in practice, and counting sort doesn't get much use.
 
* Which sorting algorithm has best asymptotic run time complexity?
 
= Python =
 
* Regex
re.match() => Matches Beginning
re.search() => Matches Anywhere
re.findall() => All Matching Objects
re.sub('[ES]', 'a', s) => Substitute
 
* Lists
 
* Dictionary
 
* File operations
Using Open:
f = open('/etc/passwd')
f.read(5)
f.close()
 
Using With Open(better, auto closes the file):
with open('/etc/passwd') as f:
for line in f:
print(line)
 
* Class
 
* OS Interaction:
 
import os
os.system("date")
 
import os
f = os.popen('date')
now = f.read()
print("Today is ", now)
 
import subprocess
subprocess.call(["ls", "-l", "/etc/resolv.conf"])
 
import subprocess
p = subprocess.Popen("date", stdout=subprocess.PIPE, shell=True)
(output, err) = p.communicate()
print("Today is", output)
 
= SMTP =
 
HELO or EHLO (Hello)
MAIL FROM
250 OK reply code
RCPT TO (Recipient To)
250 OK reply code
DATA
345 reply code
250 OK code
QUIT
221 code
 
RSET (Reset)
 
SMTP errors:
4.X.X Persistent Transient Failure
5.X.X Permanent Error: