做渗透有时候遇到已知的CMS,那我们在扫描目录的时候就不需要大字典进行,而是需要特定的字典。
如果平时要积累类似这种特定CMS的字典,会比较麻烦(因为目录文件很多,我们总不能手敲叭),所以这里写了个JAVA可以用来自动获取(这里也可以用python写)。
通过下载CMS的源文件,然后利用该脚本即可获取所有目录文件信息生成字典
鉴于有些刚入门的小朋友可能还不太理解写脚本这种思路,所以把写的过程也简单写了一下:
1、先练习将一个文件的内容读取并写入到另一个文件中:
import java.io.*;
public class Test{
public static void main(String[] args) throws IOException{
if (args[0] == null || args[1] == null){
System.out.println("请带上参数:框架文件夹位置 字典存放路径及名称");
return;
}else{
String scan_target = args[0];
String fileToWrite = args[1];
FileInputStream from_f = new FileInputStream(scan_target);//输入流
InputStreamReader reader = new InputStreamReader(from_f,"UTF-8");//读取流,编码window可以为gbk
FileOutputStream to_f = new FileOutputStream(fileToWrite);//输出流
OutputStreamWriter writer = new OutputStreamWriter(to_f,"UTF-8");//写入流,编码window可以为gbk
while (reader.ready()){
writer.append((char)reader.read());
}
writer.close();
to_f.close();
reader.close();
from_f.close();
}
}
}
image.png
image.png
或者如下代码:
import java.io.*;
public class Test{
public static void main(String[] args) throws IOException{
if (args[0] == null || args[1] == null){
System.out.println("请带上参数:框架文件夹位置 字典存放路径及名称");
return;
}else{
String scan_target = args[0];
String fileToWrite = args[1];
FileInputStream from_f = new FileInputStream(scan_target);//输入流
InputStreamReader reader = new InputStreamReader(from_f,"UTF-8");//读取流,编码window可以为gbk
StringBuffer sb = new StringBuffer();
while (reader.ready()){
sb.append((char)reader.read());
}
reader.close();
from_f.close();
FileOutputStream to_f = new FileOutputStream(fileToWrite);//输出流
OutputStreamWriter writer = new OutputStreamWriter(to_f,"UTF-8");//写入流,编码window可以为gbk
writer.append(sb);
writer.close();
to_f.close();
}
}
}
2、读取文件改为CMS根目录,并增加函数进行递归
import java.io.*;
public class Scan_frame{
//window的脚本
public static void main(String[] args) throws IOException {
try{
String scan_target = args[0];
String fileToWrite = args[1];
FileOutputStream to_f = new FileOutputStream(fileToWrite);//输出流
OutputStreamWriter writer = new OutputStreamWriter(to_f,"UTF-8");//写入流,编码window可以为gbk
File f = new File(scan_target);
String connect = f.getName();
DirList(writer,f,connect);
writer.close();
to_f.close();
}catch(ArrayIndexOutOfBoundsException e){
System.out.println("请带上两个参数:扫描目标位置 字典存放位置");
}
}
static void DirList(OutputStreamWriter writer,File target,String connect) throws IOException {
File[] files = target.listFiles();//该函数返回一个File数组,如果文件对象是一个文件,则返回null值
if (files != null){
for (File file : files){
String connect_str = connect + "/" + file.getName();
DirList(writer,file,connect_str);
}
}else{
String line = connect;
line = line + "\n";
writer.append(line);
}
}
}
效果:
image.png