You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Injection flaws occur when untrusted data is sent to an interpreter as part of a command or query. The attacker’s hostile data can trick the interpreter into executing unintended commands or accessing data without proper authorization.
22
22
</div>
23
23
</div>
24
-
<!--
25
-
<div class="panel panel-info">
26
-
<div class="panel-heading">
27
-
<h3 class="panel-title">Real World Attack Incident Examples</h3>
28
-
</div>
29
-
<div class="panel-body">
30
-
Screencast here ...
31
-
</div>
32
-
</div>
24
+
<!--
25
+
<div class="panel panel-info">
26
+
<div class="panel-heading">
27
+
<h3 class="panel-title">Real World Attack Incident Examples</h3>
28
+
</div>
29
+
<div class="panel-body">
30
+
Screencast here ...
31
+
</div>
32
+
</div>
33
33
-->
34
34
</div>
35
35
</div>
@@ -308,6 +308,95 @@ <h3 class="panel-title">How Do I Prevent It?</h3>
Log injection vulnerabilities enable an attacker to forge and tamper with an application's logs.
332
+
</p>
333
+
</div>
334
+
</div>
335
+
336
+
<divclass="panel panel-default">
337
+
<divclass="panel-heading">
338
+
<h3class="panel-title">Attack Mechanics</h3>
339
+
</div>
340
+
<divclass="panel-body">
341
+
<p>An attacker may craft a malicious request that may deliberately fail, which the application will log, and when attacker's user input is unsanitized, the payload is sent as-is to the logging facility. Vulnerabilities may vary depending on the logging facility:</p>
342
+
<h5>1. Log Forging (CRLF) </h5>
343
+
<p>Lets consider an example where an application logs a failed attempt to login to the system. A very common example for this is as follows:
344
+
</p>
345
+
<pre>
346
+
var userName = req.body.userName;
347
+
console.log('Error: attempt to login with invalid user: ', userName);
348
+
</pre>
349
+
<p>When user input is unsanitized and the output mechanism is an ordinary terminal stdout facility then the application will be vulnerable to CRLF injection, where an attacker can create a malicious payload as follows:
350
+
<pre>
351
+
curl http://localhost:4000/login -X POST --data 'userName=vyva%0aError: alex moldovan failed $1,000,000 transaction&password=Admin_123&_csrf='
352
+
</pre>
353
+
Where the <code>userName</code> parameter is encoding in the request the LF symbol which will result in a new line to begin. Resulting log output will look as follows:
354
+
<pre>
355
+
Error: attempt to login with invalid user: vyva
356
+
Error: alex moldovan failed $1,000,000 transaction
357
+
</pre>
358
+
<br/>
359
+
<h5>2. Log Injection Escalation </h5>
360
+
<p>
361
+
An attacker may craft malicious input in hope of an escalated attack where the target isn't the logs themselves, but rather the actual logging system. For example, if an application has a back-office web app that manages viewing and tracking the logs, then an attacker may send an XSS payload into the log, which may not result in log forging on the log itself, but when viewed by a system administrator on the log viewing web app then it may compromise it and result in XSS injection that if the logs app is vulnerable.
362
+
</p>
363
+
364
+
<divclass="panel panel-default">
365
+
<divclass="panel-heading">
366
+
<h3class="panel-title">How Do I Prevent It?</h3>
367
+
</div>
368
+
<divclass="panel-body">
369
+
370
+
As always when dealing with user input:
371
+
<ul>
372
+
<li>
373
+
Do not allow user input into logs
374
+
</li>
375
+
<li>
376
+
Encode to proper context, or sanitize user input
377
+
</li>
378
+
</ul>
379
+
380
+
Encoding example:
381
+
<pre>
382
+
// Step 1: Require a module that supports encoding
383
+
var ESAPI = require('node-esapi');
384
+
// - Step 2: Encode the user input that will be logged in the correct context
385
+
// following are a few examples:
386
+
console.log('Error: attempt to login with invalid user: %s', ESAPI.encoder().encodeForHTML(userName));
387
+
console.log('Error: attempt to login with invalid user: %s', ESAPI.encoder().encodeForJavaScript(userName));
388
+
console.log('Error: attempt to login with invalid user: %s', ESAPI.encoder().encodeForURL(userName));
389
+
</pre>
390
+
391
+
For the above Log Injection vulnerability, example and fix can be found at
0 commit comments