ports

References

Summary

Source Port: a random large number assigned by your laptop to keep track of an outgoing request

Destination Port: A standardized number that tells the receiver where the received data belongs

There are 65,535 ports

Sockets: are IPs + ports

When you open different browser tabs, each tab gets its own port

Nmap Tool

Windows opens a bunch of ports by default, for things like Remote Procedure Calls (RPCs, port 135) and Server Message Blocks (SMBs, port 445)

RCP: when a program makes an RCP cal, the local system packages (marshals) the request, and sends it to the remote system. The remote system executes the task and sends the result back.

SMB: The language that Windows uses for file sharing, printer sharing, ect.

Windows computers are very noisy

EternalBlue was a powerful exploit of SMBs

SMBv1 driver (srv.sys)

SMB_COM_NT_TRANSACT uses dwords, while SMB_COM_TRANSACTION2_SECONDARY uses words.

Buffer Overflow

A buffer is a temporary storage area in RAM Many old programming languages, like C and C++ don't actually check if data is small enough to fit in a buffer. If the data is too large, it overflows into the neighbouring memory addresses.

The Return Address (RET) tells the CPU to return to the main program

Address Space Layout Randomization (ASLR) Every time the computer boots, it randomizes its addresses. This makes it harder for an attacker to know the address of their malicious code

No Operation Sled (NOP Sled) The shellcode has its first 1000 bytes NOPs; the malicious code is at the end. Then, if the return address gets changed to something that hits any of those NOPs, the CPU will slide along the address until it reaches the malicious code

Runtimes Programming languages like Python and Java have this: it checks to make sure that there are no buffer overflows. In a language like C, raw instructions are just sent to the CPU. The CPU doesn't know about buffers and their sizes, so it allows buffer overflows.

Garbage collectors are background processes inside of the runtime. They look for pieces of memory that the program is no longer using, to reclaim tem for future use

Runtime Bounds Checking: this is what handles buffer overflows

But Python is written in C

Memory-Safe Systems Languages Things like C — very low level — but memory safe

Resource Exhaustion (DoS) Regex DoS (ReDoS): the attacker sends a string to a regex checker that has exponential growth

Data Execution Prevention (DEP/NX) Marks the buffers as non-executable

Return-Oriented Programming (ROP) Instead of injecting their own code, attackers stitch together pieces of legitimate code in a computer's memory to perform an attack

Heap Grooming/Spraying