当前位置:网站首页>Application Security Series 37: log injection
Application Security Series 37: log injection
2022-07-06 05:32:00 【jimmyleeee】
The parameters entered by the user are directly written to the log file without any verification , Cause attackers to pass special characters (\r \n) Inject new log entries into the log , Destroy the integrity of the system log . for example :test failed to log in. If test It's controllable , You can input (admin login successfully.\r\n test) Modify the log to :admin login successfully.\r\n Info:test failed to log in. Just inject a log . once The integrity of the log cannot be guaranteed , that , Will affect its validity as evidence .
The sample code of log injection is as follows :
logger.info("Test for Log injection for special char CRLF \r\n End");
logger.info("Test for Log injection for special char CR \r End");
logger.info("Test for Log injection for special char LF \n End");
stay windows Under the system , Run this code , The results are as follows :
It can be seen from the displayed results , It was originally a line of logs , But it shows two lines in the log , That is, a line of log is injected . What's strange here is , When using \r when , all \r All previous logs are not displayed . in other words , Whether the attacker can hide his traces through this method ???
Line breaks vary from system to system , therefore , You can also filter according to different systems .
operating system | File newline |
Windows | \r\n |
Linux | \n |
Mac | \r\n |
One of the ways to prevent Namely , escape , take \r Replace the character with \\r,\n Replace with \\n, This can make \r perhaps \n Handle as characters that are not newlines , The sample code is as follows :
logger.info("Test for Log injection for special char CRLF \\r\\n End");
logger.info("Test for Log injection for special char CR \\r End");
logger.info("Test for Log injection for special char LF \\n End");
The result is :
You can see here , take \r and \n Print out as specific characters .
The second method of prevention Is the use Log4j The configuration of automatically handles the processing of the characters that cause the injection , Although the principle will \r Replace with \\r,\n Replace with \\n, however , It's easier to use , For details, please refer to : Log4j – Log4j 2 Layouts
have access to %enc{%m}{CRLF} Replace line breaks . The specific configuration is as follows :
<Appenders>
<Console name="console" target="SYSTEM_OUT" follow="true">
<PatternLayout pattern="[%d{yyyy-MM-dd HH:mm:ss.SSS}][%-5p] [%t] [%c{10}#%M:%L] %enc{%m}{CRLF} %n "/>
</Console>
</Appenders>
It can also be used log4j The security measures provided by the framework realize automatic replacement .
Another attack against log injection , When the system maintenance personnel check the log , The log may be displayed in web On the page , If the log contains html label , May lead to XSS attack . This point , stay Log4j 2 Layouts It is also described in , have access to HTML Code to achieve , for example :%enc{%m}{HTML}.
边栏推荐
- Closure, decorator
- Summary of deep learning tuning tricks
- C进阶-数据的存储(上)
- 【OSPF 和 ISIS 在多路访问网络中对掩码的要求】
- 无代码六月大事件|2022无代码探索者大会即将召开;AI增强型无代码工具推出...
- 自建DNS服务器,客户端打开网页慢,解决办法
- Codeless June event 2022 codeless Explorer conference will be held soon; AI enhanced codeless tool launched
- UCF(暑期团队赛二)
- Promotion hung up! The leader said it wasn't my poor skills
- [force buckle]43 String multiplication
猜你喜欢
Codeless June event 2022 codeless Explorer conference will be held soon; AI enhanced codeless tool launched
JS array list actual use summary
[mask requirements of OSPF and Isis in multi access network]
Review of double pointer problems
Vulhub vulnerability recurrence 68_ ThinkPHP
How to use PHP string query function
C Advanced - data storage (Part 1)
The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
nacos-高可用seata之TC搭建(02)
Vulhub vulnerability recurrence 71_ Unomi
随机推荐
Game push: image / table /cv/nlp, multi-threaded start!
SQLite add index
Vite configures the development environment and production environment
Yyds dry inventory SSH Remote Connection introduction
The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
Knowledge points of circular structure
Promise summary
Figure database ongdb release v-1.0.3
Improve jpopup to realize dynamic control disable
UCF(暑期团队赛二)
29io stream, byte output stream continue write line feed
Vulhub vulnerability recurrence 71_ Unomi
The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
Easy to understand I2C protocol
Graduation design game mall
Three methods of Oracle two table Association update
[leetcode daily question] number of enclaves
Modbus protocol communication exception
Talking about the type and function of lens filter
Tetris