Log Injection

Log Injection is a very simple to carry out attack aimed at web applications. For the attacker its very simple to perform the attack. However, for the target web application or its administrator its very difficult to identify the scope of the attack performed and its impact.

Web applications or any applications for the case, store huge amount of logs in the backend. They may be

  1. Crash logs : Information about when the application got crashed, reason behind the crash, affected users etc.,
  2. Error/Exception logs logs : Details like exception thrown from code, Stacktrace of the thrown exception.
  3. Access logs : Access logs hold information about different end points accessed by a user in the system with time details.
  4. GC logs : Usually stored by Java to keep track of Garbage collection.
  5. Monitoring logs : Its useful when a user tries to do a suspicious activity on your site, you could detect it and send a mail to yourself to get notified or log it for future records.
  6. Apart from these, there are many categories of application logs. These logs are very useful and absolutely necessary to debug application issues, audit and control, application performance monitoring, troubleshooting etc.,

    These generated logs might be written to a disk, raised as an alert mail, pushed to a third party storage service or simply written to a set of files based on the criticalness of the generated log data and/or based on the volume of data that is generated.

    When not handled properly, even logs could be manipulated in the web application. Let’s say you have an endpoint like below,



    https://www.testsite.com/logDOSAttemptByUser?userName=user1
    

    This API will log the user names of users who are trying a DOS Attack in your site.

    And in the backend, you have something like,

    List suspiciousAccountsLogged = new ArrayList();
    suspiciousAccountsLogged = parseUserNamesFromLogs();
    if(suspiciousAccountsLogged.size > 0)
    {
      for(String userName : suspiciousAccountsLogged)
       {
          doBlockUserForDOSAttempt(userName);
       }
    }
    

    The idea is to block users who are trying to perform a DOS Attack on your site. You may find this based on the number of requests your servers have received from the particular user in a unit of time. Like above, there may be an automated way to process logs after sometime and flush data.

    Since the endpoint /logDOSAttemptByUser might be visible to the external world, it has the possibility of getting exploited. An attacker could modify the userName parameter of the request like below,

    https://www.testsite.com/logDOSAttemptByUser?userName=user2
    

    and the system could block an credible user (user2) who haven’t tried any DOS Attempt on your site, but since the logs have been injected, the system will block the user.

    Even if the logs are processed manually, it will be very cumbersome to differntiate valid logs from the injected ones and may be impossible at some cases. Log details being untrustworthy will result in serious problems.

    It is also possible to confuse the administrator with modified log messages like below.,

    https://www.testsite.com/logUsageLimitReached?msg=UsageReached
    

    This could be modified as,

    https://www.testsite.com/logUsageLimitReached?msg=UsageReached+"\n INFO : Looks like problem with our calculation"
    

    and logs would be generated as,

    INFO : UsageReached
    INFO : Looks like problem with our calculation.
    

    Solutions