Skip to content

Commit 5ac2ed7

Browse files
author
ydhcui
committed
更新插件入口
更新插件入口
1 parent 35771fe commit 5ac2ed7

File tree

12 files changed

+2219
-1977
lines changed

12 files changed

+2219
-1977
lines changed

README.md

Lines changed: 53 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -70,82 +70,104 @@ dll.main()
7070

7171

7272
4、插件系统 生成dll/so插件, 以plug_name_nps.dll格式命名放到plugins文件夹下面 即可动态调用
73-
插件开发示例, main传入插件运行参数 传出返回的内容值
73+
插件开发示例, plugmain传入插件运行参数 传出返回的内容值
7474
```rust
75-
/*
7675
//./Cargo.toml
76+
7777
[lib]
7878
path = "src/lib.rs"
7979
crate-type = ["cdylib"]
80-
*/
80+
8181

8282
//src/lib.rs
8383

8484
use std::ffi::CStr;
8585
use std::ffi::CString;
8686
use std::os::raw::c_char;
8787

88+
use protobuf::Message;
89+
use protobuf::RepeatedField;
90+
8891
#[no_mangle]
89-
pub unsafe extern "C" fn main(args: *const c_char) -> *const c_char {
90-
let r_str = CStr::from_ptr(args).to_str().unwrap();
92+
pub unsafe extern "C" fn plugmain(s: *const c_char) -> *const c_char {
93+
let r_str = CStr::from_ptr(s).to_str().unwrap();
94+
95+
let mut prs = Vec::<plug::PassResult>::new();
96+
prs.push(plug::PassResult::new());
97+
98+
let mut gret = plug::PlugResult{
99+
name: "test".to_string(),
100+
args: args.to_string(),
101+
resulttype: plug::ResultType::PASSRET,
102+
..Default::default()
103+
};
104+
gret.set_passresult(RepeatedField::from_vec(prs));
105+
106+
let c_str = gret.write_to_bytes().expect("protobuf to bytes err");
91107

92-
println!("plugin load args: {}", r_str);
93-
let c_str = format!("plugin return {}",r_str);
94108

95109
CString::new(c_str).expect("CString failed").into_raw()
96110
}
97111

112+
98113
```
99114
返回值匹配到如下protobuf格式后后将结果写入数据库
100115

101116
```protobuf
117+
102118
syntax = "proto3";
103119
104-
message PassResult{
120+
121+
enum ResultType {
122+
PASSRET = 0;
123+
PORTRET = 1;
124+
HTTPRET = 2;
125+
}
126+
127+
message PassResult {
105128
string username = 1;
106129
string password = 2;
107130
string passtype = 3;
108131
string passfrom = 4;
109132
}
110133
111-
message PassScan{
112-
string hosts = 1;
113-
string ports = 2;
114-
string args = 3;
115-
repeated PortResult result = 4;
116-
}
117-
118-
message PortResult{
134+
message PortResult {
119135
string host = 1;
120-
string port = 2;
136+
int32 port = 2;
121137
string proto = 3;
122138
string version = 4;
123139
}
124-
message PortScan{
125-
string hosts = 1;
126-
string ports = 2;
127-
string args = 3;
128-
repeated PortResult result = 4;
129-
}
130-
message HttpResult{
140+
141+
message HttpResult {
131142
string proto = 1;
132143
string host = 2;
133-
string port = 3;
144+
int32 port = 3;
134145
string title = 4;
135146
string note = 5;
136147
}
137-
message HttpScan{
138-
string hosts = 1;
139-
string ports = 2;
140-
string args = 3;
141-
repeated PortResult result = 4;
148+
149+
message PlugResult {
150+
string name = 1;
151+
string args = 2;
152+
ResultType resulttype = 3;
153+
repeated PassResult passresult = 11;
154+
repeated PortResult portresult = 12;
155+
repeated HttpResult httpresult = 13;
142156
}
143157
144158
```
145-
146159

147160
## 更新
148161

162+
### 0.6 todo
163+
164+
1、npc.exe分阶段加载,完成npc.ps1 和 npc.sh
165+
166+
2、更新getinfo,useoss,useproxy等插件
167+
168+
3、rust重写nps?
169+
170+
149171
### v0.5
150172
1、修复安全漏洞
151173

manjusaka

12 KB
Binary file not shown.

plug_demo/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,7 @@ crate-type = ["cdylib"]
1616

1717

1818
[dependencies]
19+
protobuf = "2.27.1"
1920

21+
[build-dependencies]
22+
protobuf-codegen-pure = "2.27.1"

plug_demo/build.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
fn main() {
2+
protobuf_codegen_pure::Codegen::new()
3+
.out_dir("src")
4+
.inputs(&["plug.proto"])
5+
.include("./")
6+
.run()
7+
.expect("Codegen failed.");
8+
}

plug_demo/plug.proto

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
syntax = "proto3";
2+
3+
enum ResultType {
4+
PASSRET = 0;
5+
PORTRET = 1;
6+
HTTPRET = 2;
7+
}
8+
9+
message PassResult {
10+
string username = 1;
11+
string password = 2;
12+
string passtype = 3;
13+
string passfrom = 4;
14+
}
15+
16+
message PortResult {
17+
string host = 1;
18+
int32 port = 2;
19+
string proto = 3;
20+
string version = 4;
21+
}
22+
23+
message HttpResult {
24+
string proto = 1;
25+
string host = 2;
26+
int32 port = 3;
27+
string title = 4;
28+
string note = 5;
29+
}
30+
31+
message PlugResult {
32+
string name = 1;
33+
string args = 2;
34+
ResultType resulttype = 3;
35+
repeated PassResult passresult = 11;
36+
repeated PortResult portresult = 12;
37+
repeated HttpResult httpresult = 13;
38+
}
39+
40+

plug_demo/src/lib.rs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,26 @@ use std::ffi::CStr;
22
use std::ffi::CString;
33
use std::os::raw::c_char;
44

5+
use protobuf::Message;
6+
use protobuf::RepeatedField;
7+
58
#[no_mangle]
6-
pub unsafe extern "C" fn main(s: *const c_char) -> *const c_char {
9+
pub unsafe extern "C" fn plugmain(s: *const c_char) -> *const c_char {
710
let r_str = CStr::from_ptr(s).to_str().unwrap();
811

9-
println!("plugin load: {}", r_str);
10-
let c_str = format!("plugin return {}",r_str);
12+
let mut prs = Vec::<plug::PassResult>::new();
13+
prs.push(plug::PassResult::new());
14+
15+
let mut gret = plug::PlugResult{
16+
name: "test".to_string(),
17+
args: args.to_string(),
18+
resulttype: plug::ResultType::PASSRET,
19+
..Default::default()
20+
};
21+
gret.set_passresult(RepeatedField::from_vec(prs));
22+
23+
let c_str = gret.write_to_bytes().expect("protobuf to bytes err");
24+
1125

1226
CString::new(c_str).expect("CString failed").into_raw()
1327
}

plugins/libnpc.a

Lines changed: 2098 additions & 1943 deletions
Large diffs are not rendered by default.

plugins/libnpc.so

36 KB
Binary file not shown.

plugins/npc

0 Bytes
Binary file not shown.

plugins/npc.dll

0 Bytes
Binary file not shown.

plugins/npc.exe

0 Bytes
Binary file not shown.

plugins/plug_getpass_nps.dll

919 KB
Binary file not shown.

0 commit comments

Comments
 (0)