Skip to content

Commit e1c6189

Browse files
committed
created fusemounts handler
1 parent 25870eb commit e1c6189

File tree

11 files changed

+270
-6
lines changed

11 files changed

+270
-6
lines changed

cSploit/jni/cSploitClient/cache.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ int init_csploit_events_cache(JNIEnv *env) {
132132
{ "org/csploit/android/events/Login", "(ILjava/net/InetAddress;Ljava/lang/String;Ljava/lang/String;)V" },
133133
{ "org/csploit/android/events/Attempts", "(JJJJJ)V" },
134134
{ "org/csploit/android/events/Packet", "(Ljava/net/InetAddress;Ljava/net/InetAddress;S)V" },
135+
{ "org/csploit/android/events/FuseBind", "(Ljava/lang/String;Ljava/lang/String;)V" },
135136
};
136137
struct class_and_ctor_cache *ptr;
137138
register int i;

cSploit/jni/cSploitClient/cache.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ struct events_cache {
4343
message,
4444
login,
4545
attempts,
46-
packet;
46+
packet,
47+
fusebind;
4748
};
4849

4950
struct core_chlidmanager_cache {

cSploit/jni/cSploitClient/event.c

Lines changed: 72 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include "ettercap.h"
3232
#include "arpspoof.h"
3333
#include "tcpdump.h"
34+
#include "fusemounts.h"
3435

3536
#include "event.h"
3637

@@ -110,7 +111,7 @@ jobject create_stderrnewline_event(JNIEnv *env, void *arg) {
110111
/**
111112
* @brief create an org.csploit.android.events.ChildEnd
112113
* @param arg a pointer to the exit status
113-
* @returns the jobject on success, NULLl on error.
114+
* @returns the jobject on success, NULL on error.
114115
*/
115116
jobject create_child_end_event(JNIEnv *env, void *arg) {
116117
jobject event;
@@ -133,7 +134,7 @@ jobject create_child_end_event(JNIEnv *env, void *arg) {
133134
/**
134135
* @brief create an org.csploit.android.events.ChildDied
135136
* @param arg a poitner to the signal that caused the death
136-
* @returns the jobject on success, NULLl on error.
137+
* @returns the jobject on success, NULL on error.
137138
*/
138139
jobject create_child_died_event(JNIEnv *env, void *arg) {
139140
jobject event;
@@ -185,7 +186,7 @@ jobject inaddr_to_inetaddress(JNIEnv *env, in_addr_t a) {
185186
/**
186187
* @brief create an org.csploit.android.events.Hop
187188
* @param arg a pointer to an ::nmap_hop_info
188-
* @returns the jobject on success, NULLl on error.
189+
* @returns the jobject on success, NULL on error.
189190
*/
190191
jobject create_hop_event(JNIEnv *env, void *arg) {
191192
jobject addr, res;
@@ -473,6 +474,12 @@ jobject create_message_event(JNIEnv *env, message *m) {
473474
(*env)->ExceptionClear(env);
474475
}
475476

477+
if(jseverity)
478+
(*env)->DeleteLocalRef(env, jseverity);
479+
480+
if(jmessage)
481+
(*env)->DeleteLocalRef(env, jmessage);
482+
476483
return res;
477484
}
478485

@@ -565,7 +572,7 @@ jobject create_login_event(JNIEnv *env, message *m) {
565572
/**
566573
* @brief create an org.csploit.android.events.Packet
567574
* @param m the received message
568-
* @returns the jobject on success, NULLl on error.
575+
* @returns the jobject on success, NULL on error.
569576
*/
570577
jobject create_packet_event(JNIEnv *env, message *m) {
571578
jobject src, dst, res;
@@ -595,6 +602,67 @@ jobject create_packet_event(JNIEnv *env, message *m) {
595602
return res;
596603
}
597604

605+
/**
606+
* @brief create an org.csploit.android.events.FuseBind
607+
* @param m the received message
608+
* @returns the jobject on success, NULL on error.
609+
*/
610+
jobject create_fusebind_event(JNIEnv *env, message *m) {
611+
jobject res;
612+
char *src, *mnt;
613+
jstring *jsrc, *jmnt;
614+
struct fusemount_bind_info *bind_info;
615+
616+
bind_info = (struct fusemount_bind_info *) m->data;
617+
jsrc = jmnt = NULL;
618+
619+
src = string_array_next(m, bind_info->data, NULL);
620+
621+
if(!src) {
622+
LOGE("%s: source not found", __func__);
623+
return NULL;
624+
}
625+
626+
mnt = string_array_next(m, bind_info->data, src);
627+
628+
if(!mnt) {
629+
LOGE("%s: mountpoint not found", __func__);
630+
return NULL;
631+
}
632+
633+
jsrc = (*env)->NewStringUTF(env, src);
634+
635+
if(!jsrc) goto jni_error;
636+
637+
jmnt = (*env)->NewStringUTF(env, mnt);
638+
639+
if(!jmnt) goto jni_error;
640+
641+
res = (*env)->NewObject(env,
642+
cache.csploit.events.fusebind.class,
643+
cache.csploit.events.fusebind.ctor,
644+
jsrc, jmnt);
645+
646+
goto cleanup;
647+
648+
jni_error:
649+
650+
if((*env)->ExceptionCheck(env)) {
651+
(*env)->ExceptionDescribe(env);
652+
(*env)->ExceptionClear(env);
653+
}
654+
655+
cleanup:
656+
657+
if(jsrc)
658+
(*env)->DeleteLocalRef(env, jsrc);
659+
660+
if(jmnt)
661+
(*env)->DeleteLocalRef(env, jmnt);
662+
663+
return res;
664+
}
665+
598666
/**
599667
* @brief send an event to java.
600668
* @param c the child that generate this event

cSploit/jni/cSploitClient/event.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ jobject create_message_event(JNIEnv *, message *);
3636
jobject create_login_event(JNIEnv *, message *);
3737
jobject create_attempts_event(JNIEnv *, message *);
3838
jobject create_packet_event(JNIEnv *, message *);
39+
jobject create_fusebind_event(JNIEnv *, message *);
3940
int send_event(JNIEnv *, child_node *, jobject);
4041

4142
#endif

cSploit/jni/cSploitClient/handler.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,8 @@ int on_handler_list(message *m) {
195195
handlers.by_name.arpspoof = h;
196196
} else if(!handlers.by_name.tcpdump && !strncmp(h->name, "tcpdump", 8)) {
197197
handlers.by_name.tcpdump = h;
198+
} else if(!handlers.by_name.fusemounts && !strncmp(h->name, "fusemounts", 11)) {
199+
handlers.by_name.fusemounts = h;
198200
}
199201

200202
h->id = handler_info->id;

cSploit/jni/cSploitClient/handler.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ extern struct handlers_list {
5353
handler *hydra;
5454
handler *arpspoof;
5555
handler *tcpdump;
56+
handler *fusemounts;
5657
} by_name; ///< access handlers by name
5758
enum handlers_loading_status status;
5859
} handlers;

cSploit/jni/cSploitClient/notifier.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include "hydra.h"
3838
#include "arpspoof.h"
3939
#include "tcpdump.h"
40+
#include "fusemounts.h"
4041

4142
#include "notifier.h"
4243

@@ -229,6 +230,35 @@ int on_tcpdump(JNIEnv *env, child_node *c, message *m) {
229230
return ret;
230231
}
231232

233+
int on_fusemounts(JNIEnv *env, child_node *c, message *m) {
234+
jobject event;
235+
int ret;
236+
237+
ret = -1;
238+
239+
switch(m->data[0]) {
240+
case FUSEMOUNT_BIND:
241+
event = create_fusebind_event(env, m);
242+
break;
243+
default:
244+
LOGW("%s: unkown fusemount action: %02hhX", __func__, m->data[0]);
245+
return -1;
246+
}
247+
248+
if(!event) {
249+
LOGE("%s: cannot create event", __func__);
250+
} else if(send_event(env, c, event)) {
251+
LOGE("%s: cannot send event", __func__);
252+
} else {
253+
ret = 0;
254+
}
255+
256+
if(event)
257+
(*env)->DeleteLocalRef(env, event);
258+
259+
return ret;
260+
}
261+
232262
int on_message(JNIEnv *env, message *m) {
233263
child_node *c;
234264
int ret;
@@ -263,6 +293,8 @@ int on_message(JNIEnv *env, message *m) {
263293
ret = on_arpspoof(env, c, m);
264294
} else if( c->handler == handlers.by_name.tcpdump) {
265295
ret = on_tcpdump(env, c, m);
296+
} else if( c->handler == handlers.by_name.fusemounts) {
297+
ret = on_fusemounts(env, c, m);
266298
} else {
267299
LOGW("%s: unkown handler: \"%s\" ( #%u )", __func__, c->handler->name, c->handler->id);
268300
}
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
/* cSploit - a simple penetration testing suite
2+
* Copyright (C) 2014 Massimo Dragano aka tux_mind <[email protected]>
3+
*
4+
* cSploit is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* cSploit is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with cSploit. If not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
18+
#include <string.h>
19+
#include <regex.h>
20+
21+
#include "handler.h"
22+
#include "logger.h"
23+
#include "fusemounts.h"
24+
#include "message.h"
25+
#include "str_array.h"
26+
27+
handler handler_info = {
28+
NULL, // next
29+
7, // handler id
30+
0, // have_stdin
31+
1, // have_stdout
32+
1, // enabled
33+
NULL, // raw_output_parser
34+
&fusemounts_output_parser, // output_parser
35+
NULL, // input_parser
36+
"tools/fusemounts/fusemounts", // argv[0]
37+
NULL, // workdir
38+
"fusemounts" // handler name
39+
};
40+
41+
/**
42+
* @brief extract fusemount source and destination from fusemounts output
43+
* @param line the line to parse
44+
* @returns a message to send or NULL
45+
*/
46+
message *fusemounts_output_parser(char *line) {
47+
message *m;
48+
char *dst, *ptr;
49+
50+
if(!*line) {
51+
return NULL;
52+
}
53+
54+
for(dst=line;*dst!=' ' && *dst!='\0';dst++);
55+
56+
if(*dst) {
57+
*dst='\0';
58+
dst++;
59+
}
60+
61+
for(;*dst==' ';dst++);
62+
63+
if(!*dst)
64+
return NULL;
65+
66+
for(ptr=dst;*ptr!=' ' && *ptr!='\0';ptr++);
67+
*ptr='\0';
68+
69+
m = create_message(0, sizeof(struct fusemount_bind_info), 0);
70+
71+
if(!m) {
72+
print(ERROR, "cannot create messages");
73+
return NULL;
74+
}
75+
76+
m->data[0] = FUSEMOUNT_BIND;
77+
78+
if(string_array_add(m, offsetof(struct fusemount_bind_info, data), line)) {
79+
print( ERROR, "cannot append string to message" );
80+
goto error;
81+
}
82+
83+
if(string_array_add(m, offsetof(struct fusemount_bind_info, data), dst)) {
84+
print( ERROR, "cannot append string to message" );
85+
goto error;
86+
}
87+
88+
return m;
89+
90+
error:
91+
free_message(m);
92+
93+
return NULL;
94+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/* cSploit - a simple penetration testing suite
2+
* Copyright (C) 2014 Massimo Dragano aka tux_mind <[email protected]>
3+
*
4+
* cSploit is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* cSploit is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with cSploit. If not, see <http://www.gnu.org/licenses/>.
16+
*
17+
*
18+
*/
19+
#ifndef HANDLERS_FUSEMOUNTS_H
20+
#define HANDLERS_FUSEMOUNTS_H
21+
22+
enum fusemount_action {
23+
FUSEMOUNT_BIND
24+
};
25+
26+
struct fusemount_bind_info {
27+
char fusemount_action; ///< must be set to ::FUSEMOUNT_BIND
28+
/**
29+
* @brief string array containing mount source and destination
30+
*
31+
* data[0] is the source path
32+
* data[1] is the destination path
33+
*/
34+
char data[];
35+
};
36+
37+
message *fusemounts_output_parser(char *);
38+
39+
#endif
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package org.csploit.android.events;
2+
3+
/**
4+
* a new fuse mountpoint has been found
5+
*/
6+
public class FuseBind implements Event {
7+
public final String source, mountpoint;
8+
9+
public FuseBind(String source, String mountpoint) {
10+
this.source = source;
11+
this.mountpoint = mountpoint;
12+
}
13+
14+
@Override
15+
public String toString() {
16+
return String.format("FuseBind: { source='%s', mountpoint='%s' }", this.source, this.mountpoint);
17+
}
18+
}

0 commit comments

Comments
 (0)