- 浏览: 667806 次
- 性别:
- 来自: 杭州
-
文章分类
最新评论
-
HkEndless:
不好意思,请问这确定是回调机制吗。你的例子中只是将接口的实现类 ...
Spring CallBack回调机制介绍 -
hanmiao:
写的真乱啊,完全不知所云...
Java如何调用可执行文件和批处理命令 -
junia_1:
junia_1 写道 shock: ...
为什么要使用EJB -
junia_1:
shock:
为什么要使用EJB -
coollifer:
不错
SQL Server数据导入到Oracle中的方法
Overview
Command injection vulnerabilities allow an attacker to inject arbitrary system commands into an application. The commands execute at the same privilege level as the Java application and provides an attacker with functionality similar to a system shell. In Java, Runtime.exec is often used to invoke a new process, but it does not invoke a new command shell, which means that chaining or piping multiple commands together does not usually work. Command injection is still possible if the process spawned with Runtime.exec is a command shell like command.com, cmd.exe, or /bin/sh.
Examples
Example 1
The code below allows a user to control the arguments to the Window's find command. While the user does have full control over the arguments, it is not possible to inject additional commands. For example, inputting “test & del file” will not cause the del command to execute, since Runtime.exec tokenizes the command string and then invokes the find command using the parameters “test”, “&”, “del”, and “file.”
import java.io.*; public class Example1 { public static void main(String[] args) throws IOException { if(args.length != 1) { System.out.println("No arguments"); System.exit(1); } Runtime runtime = Runtime.getRuntime(); Process proc = runtime.exec("find" + " " + args[0]); InputStream is = proc.getInputStream(); InputStreamReader isr = new InputStreamReader(is); BufferedReader br = new BufferedReader(isr); String line; while ((line = br.readLine()) != null) { System.out.println(line); } } }
Example 2
The code below invokes the system shell in order to execute a non-executable command using user input as parameters. Non-executable Window's commands such as dir and copy are part of the command interpreter and therefore cannot be directly invoked by Runtime.exec. In this case, command injection is possible and an attacker could chain multiple commands together. For example, inputting “. & echo hello” will cause the dir command to list the contents of the current directory and the echo command to print a friendly message.
import java.io.*; public class Example2 { public static void main(String[] args) throws IOException { if(args.length != 1) { System.out.println("No arguments"); System.exit(1); } Runtime runtime = Runtime.getRuntime(); String[] cmd = new String[3]; cmd[0] = "cmd.exe" ; cmd[1] = "/C"; cmd[2] = "dir " + args[0]; Process proc = runtime.exec(cmd); InputStream is = proc.getInputStream(); InputStreamReader isr = new InputStreamReader(is); BufferedReader br = new BufferedReader(isr); String line; while ((line = br.readLine()) != null) { System.out.println(line); } } }
发表评论
-
hibernate Restrictions用法 MatchMode.ANYWHERE
2012-07-14 15:50 4011方法 说明 Res ... -
URLClassLoader
2012-05-27 19:45 1018This example shows how a serv ... -
MyClassLoader 自定义类加载器
2012-05-27 19:38 1572package demo; import java. ... -
Deal with big-endian and little-endian order
2011-12-25 19:17 1155Java virtual machine always use ... -
修改eclipse的背景色
2011-11-12 19:23 1132eclipse 操作界面默认颜色为白色。对于我们长期 ... -
多线程管道流输入输出模式
2011-11-07 07:23 1113import java.io.* ; class Send ... -
Java计数单字节双字节字符个数的例子
2011-10-26 14:29 1315/* 计数单双字符的个数并存储在Map对象中 ... -
常用内存数据库3
2011-10-24 00:24 15474.1.2 哪些场合适合使用其他的关系型数据库管 ... -
java字节码规则
2011-09-05 13:56 1282栈和局部变量操作 将常量压入栈的指令 aconst_nul ... -
Tomcat中限制ip访问
2011-08-23 21:40 1303Tomcat中限制ip访问是非常简单的,只需要编辑server ... -
一个Java程序员应该掌握的10项技能
2011-08-22 10:27 6391、语法:必须比较熟 ... -
2011 年 8 月 Java 开发人员新闻快讯
2011-08-18 18:59 859Java SE 7 发布了! 经过世界各地 Ja ... -
BlockingQueue
2011-08-13 09:59 750import java.util.concurrent.Arr ... -
eclipse中java项目转换为web项目
2011-07-27 18:29 912经常在eclipse中导入web项目时,出现转不了项目类型 ... -
Oracle官方Weblogic插件安装
2011-07-20 22:00 2907Installing Oracle Enterprise Pa ... -
Java集合HashSet-ArrayList-HashMap的线程同步控制方法和区别
2011-06-21 17:44 2350C ollections类中提供了多 ... -
关于java的集合类,以及HashMap中Set的用法
2011-06-21 17:35 1830import java.util.*; public c ... -
Java的动态代理实例
2011-06-16 03:44 1073首先写一个接口: package net.test.dyna ... -
Java如何调用可执行文件和批处理命令
2011-06-07 00:58 2397Java是种跨平台的语言,我们经常碰到需要通过Java调用wi ... -
jsp实现图片验证码的方法
2011-06-07 00:57 1414调用方法 <img src=&quo ...
相关推荐
$ java -jar JNDI-Injection-Exploit-1.0-SNAPSHOT-all.jar [-C] [command] [-A] [address] where: -C - command executed in the remote classfile. (optional , default command is "open /Applications/...
5. 命令注入(Command Injection) 6. 路径操作(Path Manipulation) 7. 跨站请求伪造(Cross-Site Request Forgery, CSRF) 8. 访问控制不当(Insecure Access Control) 9. 不安全的随机数生成(Insecure ...
DLL injection: On DLL injection failure CE tries to fall back on forced injection methods Assembler: Added multibyte NOP Plugins: Plugins can now have side dll's that are statically linked in their ...
Inversion of Control and dependency injection 24 GBeans 28 Configurations 30 This material is copyright and is licensed for the sole use by Jillian Fraser on 20th November 2009 111 Sutter Street, ...
17. Spring Beans and Dependency Injection 18. Using the @SpringBootApplication Annotation 19. Running Your Application 19.1. Running from an IDE 19.2. Running as a Packaged Application 19.3. Using the...