Skip to content

Commit

Permalink
支持自动生成默认配置文件
Browse files Browse the repository at this point in the history
  • Loading branch information
Noctiro committed Mar 22, 2022
1 parent 54f4bb0 commit 2540c36
Show file tree
Hide file tree
Showing 9 changed files with 111 additions and 82 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
## 启动软件

- 在终端执行 `java -jar stealbomb.jar` 即可使用()shiy
- 在终端执行 `java --enable-preview -jar stealbomb.jar` 即可使用
- 输出将显示在**控制台**

### 启动参数
Expand All @@ -17,7 +17,7 @@

## 文本编写

> 默认使用同一文件夹下的配置 default.properties(需自行下载: <https://cdn.jsdelivr.net/gh/ObcbO/stealbomb/default.properties>)
> 默认自动生成的 default.properties
使用Java Properties写法

Expand Down
Binary file modified bin/App.class
Binary file not shown.
2 changes: 1 addition & 1 deletion bin/default.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# ????
# Default
# byObcbO
threads=32
method=POST
Expand Down
Binary file added bin/file.class
Binary file not shown.
Binary file modified bin/post.class
Binary file not shown.
82 changes: 4 additions & 78 deletions src/App.java
Original file line number Diff line number Diff line change
@@ -1,90 +1,16 @@
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

public class App {
// 默认值
static int thnum = 1;// 线程数
static String method = "POST";// 请求方法
static String url;// 攻击网址
static String param;// 攻击参数

static boolean success = true;

public static Properties properties;

public static void main(String[] args) {
boolean success = false;
try {
file();
success = file.start();
} catch (IOException e) {
e.printStackTrace();
}
while (success) {
} // todo: gui
}

private static void file() throws IOException {
String file;
if (System.getProperty("file") == null || System.getProperty("file") == ""
|| System.getProperty("file").trim() == "") {
if (!new File("src/default.properties").exists()) {
generatefile();
}
file = "default.properties".toString();;
} else
file = System.getProperty("file").toString();
System.out.println(file);
InputStream inputStream = App.class.getClassLoader().getResourceAsStream(file);
properties = new Properties();
properties.load(inputStream);
properties.list(System.out);
manage();
System.out.println("-=-=-=-=- File processing completed");
if (success) {
post.start(thnum, method, url, param);
}
}

private static void generatefile() {
properties.setProperty("1", "123");
}

private static void manage() {
String temp;
// 线程数
temp = properties.getProperty("threads");
if (temp.matches("[0-9]*")) {
thnum = Integer.parseInt(temp);
} else {
success = false;
System.out.println("ERROR: 线程数 你输入的值不是一个正整数");
}
// 请求方法
temp = properties.getProperty("method").toUpperCase();
switch (temp) {
case "GET":
case "HEAD":
case "POST":
case "PUT":
case "DELETE":
case "CONNECT":
case "OPTIONS":
case "TRACE":
case "PATCH":
url = temp;
break;
default:
System.out.println("ERROR: 请求方法 未知的请求方法");
}
// 攻击网址
if (properties.getProperty("URL").matches("^(http|https)://([\\w-]+\\.)+[\\w-]+(/[\\w-./?%&=]*)?$")) {
url = properties.getProperty("URL");
} else {
success = false;
System.out.println("ERROR: 攻击网址 你输入的字符串不是一个网址");
System.out.println("³É¹¦! ¿ªÊ¼¹¥»÷");
}
// 参数
param = properties.getProperty("parameter");
while (success) {}
}
}
2 changes: 1 addition & 1 deletion src/default.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# ????
# Default
# byObcbO
threads=32
method=POST
Expand Down
102 changes: 102 additions & 0 deletions src/file.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Properties;

public class file {
// 默认值
static int thnum = 1;// 线程数
static String method = "POST";// 请求方法
static String url;// 攻击网址
static String param;// 攻击参数

static boolean success = true;

public static Properties properties;

static boolean start() throws IOException {
String file;
if (System.getProperty("file") == null || System.getProperty("file") == ""
|| System.getProperty("file").trim() == "") {
if (!new File("default.properties").exists()) {
generatefile();
}
file = "default.properties".toString();
;
} else
file = System.getProperty("file").toString();
System.out.println(file);
InputStream inputStream = file.class.getClassLoader().getResourceAsStream(file);
properties = new Properties();
properties.load(inputStream);
properties.list(System.out);
manage();
System.out.println("-=-=-=-=- File processing completed");
if (success) {
post.start(thnum, method, url, param);
}
return success;
}

private static void generatefile() {
try {
InputStream is = file.class.getResourceAsStream("default.properties");
File f = new File("default.properties");
if (!f.exists()) {// 文件不存在时先创建
f.createNewFile();
}
OutputStream os = new FileOutputStream(f);
int index = 0;
byte[] bytes = new byte[1024];// 指定每次读取的位数,这里以1024为例
while ((index = is.read(bytes)) != -1) {
os.write(bytes, 0, index);
}
os.flush();
os.close();
is.close();

} catch (IOException e) {
e.printStackTrace();
}
}

private static void manage() {
String temp;
// 线程数
temp = properties.getProperty("threads");
if (temp.matches("[0-9]*")) {
thnum = Integer.parseInt(temp);
} else {
success = false;
System.out.println("ERROR: 线程数 你输入的值不是一个正整数");
}
// 请求方法
temp = properties.getProperty("method").toUpperCase();
switch (temp) {
case "GET":
case "HEAD":
case "POST":
case "PUT":
case "DELETE":
case "CONNECT":
case "OPTIONS":
case "TRACE":
case "PATCH":
url = temp;
break;
default:
System.out.println("ERROR: 请求方法 未知的请求方法");
}
// 攻击网址
if (properties.getProperty("URL").matches("^(http|https)://([\\w-]+\\.)+[\\w-]+(/[\\w-./?%&=]*)?$")) {
url = properties.getProperty("URL");
} else {
success = false;
System.out.println("ERROR: 攻击网址 你输入的字符串不是一个网址");
}
// 参数
param = properties.getProperty("parameter");
}
}
1 change: 1 addition & 0 deletions src/post.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ protected static void start(int thnum, String tmethod, String turl, String tpara
method = tmethod;
url = turl;
param = tparam;
System.out.println(param);
for (int i = 0; i < thnum; i++) {
new Thread(new post()).start();
}
Expand Down

0 comments on commit 2540c36

Please sign in to comment.