Log Injection

01 Jul, 2022
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
Crash logs : Information about when the application got crashed, reason behind the crash, affected users etc.,Error/Exception logs : Details like exception thrown from code, Stacktrace of the thrown exception.Access logs : Access logs hold information about different end points accessed by a user in the system with time details.GC logs : Usually stored by Java to keep track of Garbage collection.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.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.
SolutionsInstead of directly passing messages via parameters, log codes could be passed. However it is still exploitable.Don’t use API Calls to log actions, as there API’s will be visible in browser network calls.In case of a need, pass user ids or publicly non identifiable values as parameters in logging endpoints.Use proper error codes and identifiable error messages.My Personal Notes
arrow_drop_upSave
Crash logs : Information about when the application got crashed, reason behind the crash, affected users etc.,
Error/Exception logs : Details like exception thrown from code, Stacktrace of the thrown exception.
Access logs : Access logs hold information about different end points accessed by a user in the system with time details.
GC logs : Usually stored by Java to keep track of Garbage collection.
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.
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
Instead of directly passing messages via parameters, log codes could be passed. However it is still exploitable.
Don’t use API Calls to log actions, as there API’s will be visible in browser network calls.
In case of a need, pass user ids or publicly non identifiable values as parameters in logging endpoints.
Use proper error codes and identifiable error messages.
harshmaster07705
Information-Security
Technical Scripter 2018
vulnerability
Articles
Technical Scripter
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.