Exploiting poor credential management

Let us discuss how hard coded database credentials can be exposed when an attacker gains access to the source code, followed by how credentials stored using weak hashing algorithms can be cracked and viewed in clear text.

Accessing hard coded credentials

Applications often contain hardcoded credentials to authenticate to other services such as databases. When an attacker gains access to the source code, these hard coded credentials may be found and abused. Let us see an example of how this may be done through a vulnerable web application.  We are going to target Xtreme Vulnerable Web Application (XVWA) for this example. Navigate to OS Command Injection, which is a page vulnerable to command injection. Let us enter the following payload into the text box. This looks as follows. Using command injection, we are attempting to read the file config.php from the server. The request intercepted in Burp proxy looks as follows. Send the request to repeater and trigger the request. We should be able to see the following in the HTTP response returned from the server. User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Firefox/68.0 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,/;q=0.8 Accept-Language: en-US,en;q=0.5 Accept-Encoding: gzip, deflate Referer: http://192.168.1.105/xvwa/vulnerabilities/cmdi/ Connection: close Cookie: PHPSESSID=s009kc6a731sos0p23i3gcfiq7 Upgrade-Insecure-Requests: 1 As highlighted, the database credentials are hardcoded in the config file and the credentials are in clear text.  An attacker with access to the internal infrastructure may be able to use these credentials to directly connect to the underlying database. $XVWA_WEBROOT = “”; $host = “localhost”; $dbname = ‘xvwa’; $user = “root”; $pass = “root”; $conn = new mysqli($host,$user,$pass,$dbname); $conn1 = new PDO(“mysql:host=$host;dbname=$dbname”, $user, $pass); $conn1->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); ?>