当前位置:网站首页>应用安全系列之三十七:日志注入
应用安全系列之三十七:日志注入
2022-07-06 05:29:00 【jimmyleeee】
用户输入的参数未做任何验证直接写入日志文件,导致攻击者可以通过特殊字符(\r \n)在日志中注入新的日志条目,破坏系统日志的完整性。例如:test failed to log in. 如果test是可以控制的,就可以通过输入(admin login successfully.\r\n test)将日志修改为:admin login successfully.\r\n Info:test failed to log in. 就注入了一条日志。 一旦 日志的完整性没法保障,那么,会影响它作为证据的有效性。
日志注入的示例代码如下:
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");在windows系统下,运行此代码,显示的结果如下:

从显示的结果可以看出,原本是一行日志的,却在日志中显示了两行,也就是注入了一行日志。这里比较奇怪的是,当使用\r时,所有\r之前的日志全部都没有显示。也就是说,攻击者是否可以通过此方法隐藏自己的痕迹???
不同系统的换行符也不一样,所以,也可以根据不同的系统进行针对性的过滤。
| 操作系统 | 文件换行符 |
| Windows | \r\n |
| Linux | \n |
| Mac | \r\n |
预防的方法之一就是,转义,将\r字符替换为\\r,\n替换为\\n,这一样就可以将\r或者\n处理为不是换行的字符,示例代码如下:
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");显示的结果是:

可以看到这里,将\r和\n作为具体字符打印出来。
预防的方法之二就是利用Log4j的配置自动处理这些导致注入的字符的处理,虽然原理也是将\r替换为\\r,\n替换为\\n,但是,使用起来更简单,具体可以参考: Log4j – Log4j 2 Layouts
可以使用%enc{%m}{CRLF}对换行符进行替换处理。具体配置如下:
<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>这样也可以使用log4j框架提供的安全措施实现自动替换。
针对日志注入的另外一种攻击,就是在系统维护人员查看日志时,可能会将日志显示在web页面上,如果日志中含有html标签,可能导致XSS攻击。这一点,在Log4j 2 Layouts中也有描述,可以使用HTML编码来实现,例如:%enc{%m}{HTML}.
边栏推荐
- Solution of QT TCP packet sticking
- Figure database ongdb release v-1.0.3
- Note the various data set acquisition methods of jvxetable
- 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
- [machine learning notes] univariate linear regression principle, formula and code implementation
- [QNX hypervisor 2.2 user manual]6.3.3 using shared memory (shmem) virtual devices
- Problems encountered in installing mysql8 on MAC
- Simple understanding of interpreters and compilers
- 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
- Summary of redis basic knowledge points
猜你喜欢

Codeless June event 2022 codeless Explorer conference will be held soon; AI enhanced codeless tool launched

04. Project blog log

Unity Vector3. Use and calculation principle of reflect

图数据库ONgDB Release v-1.0.3

趋势前沿 | 达摩院语音 AI 最新技术大全

Steady, 35K, byte business data analysis post

【云原生】3.1 Kubernetes平台安装KubeSpher

用StopWatch 统计代码耗时

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 IIC protocol explanation
随机推荐
Sliding window problem review
F12 solve the problem that web pages cannot be copied
算法-- 爬楼梯(Kotlin)
【torch】|torch. nn. utils. clip_ grad_ norm_
26file filter anonymous inner class and lambda optimization
无代码六月大事件|2022无代码探索者大会即将召开;AI增强型无代码工具推出...
C AES encrypts strings
Golang -- TCP implements concurrency (server and client)
Algorithm -- climbing stairs (kotlin)
Talking about the type and function of lens filter
【华为机试真题详解】检查是否存在满足条件的数字组合
Summary of redis basic knowledge points
Building intelligent gray-scale data system from 0 to 1: Taking vivo game center as an example
图数据库ONgDB Release v-1.0.3
Can the feelings of Xi'an version of "Coca Cola" and Bingfeng beverage rush for IPO continue?
Ora-01779: the column corresponding to the non key value saving table cannot be modified
UCF (2022 summer team competition I)
Compilation et connexion de shader dans games202 - webgl (comprendre la direction)
jdbc使用call调用存储过程报错
Modbus protocol communication exception