by Dilnoza Bobokalonova

Pentests: One downside of pentests is that sometimes they are just a means to check boxes for compliance purposes, are performed using simple automated scanners, and may leave big holes open.

Red Team: The idea is: in order to protect against attacks, auditors have to think and operate like real attackers.

Format String Attack is the form of attack that makes use of printf vulnerabilities that exposes the program to be messed with from the calling command line. Example:

#include  <stdio.h> 
void main(int argc, char **argv)
{
	// This line is safe
	printf("%s\n", argv[1]);

	// This line is vulnerable
	printf(argv[1]);
}

Running it with ./example "Hello World %s%s%s%s%s%s" would lead to the program’s interpretation of the %s%s%s%s%s%s in the input string as a reference to string pointers, so it will try to interpret every %s as a pointer to a string, starting from the location of the buffer (probably on the Stack). At some point, it will get to an invalid address, and attempting to access the invalid address, the program will naturally crash.

And say, running it with ./example "Hello World %p %p %p %p %p %p" will lead to the printing of addresses in memory, hence getting information that could lead to further vulnerability of the system.

Also reading and writing to any memory location is possible in some conditions, and even code execution.

Hence, the fact that Rust uses macros allows the printing to be compile-time evaluated and checked, preventing vulnerabilities such as format string vulnerabilities.

Some Rust Deep Dives

Macros

A function signature must declare the number and type of parameters the function has. Macros, on the other hand, can take a variable number of parameters: we can call println!("hello") with one argument or println!("hello {}", name)with two arguments. Also, macros are expanded before the compiler interprets the meaning of the code, so a macro can, for example, implement a trait on a given type. A function can’t, because it gets called at runtime and a trait needs to be implemented at compile time.

println! is a macro and not a function because Rust doesn’t support (yet?) variadic generics.

Variadic functions are functions that can take a variable number of arguments. In C programming, a variadic function adds flexibility to the program. It takes one fixed argument and then any number of arguments can be passed.

Type of Projects

A binary crate is an executable project that has a main() method. A library crate is a group of components that can be reused in other projects. Unlike a binary crate, a library crate does not have an entry point (main() method).

Error Handling

https://doc.rust-lang.org/rust-by-example/error/multiple_error_types/boxing_errors.html

let wordlist_file = File::open(&args[1])?;, the question mark cuts the need to use match, as the File::open will give out either Err() or Ok().

Vectors