fragattack: ignore unrelated messages on wpaspy control channel

This commit is contained in:
Mathy Vanhoef 2020-06-28 09:29:08 +04:00 committed by Mathy Vanhoef
parent 9431a8c39b
commit edaf1abf56
3 changed files with 48 additions and 2 deletions

View File

@ -3118,6 +3118,14 @@ static int hostapd_ctrl_iface_receive_process(struct hostapd_data *hapd,
socklen_t fromlen) socklen_t fromlen)
{ {
int reply_len, res; int reply_len, res;
int console = 0;
#ifdef CONFIG_TESTING_OPTIONS
if (os_strncmp(buf, "> ", 2) == 0) {
console = 1;
buf += 2;
}
#endif /* CONFIG_TESTING_OPTIONS */
os_memcpy(reply, "OK\n", 3); os_memcpy(reply, "OK\n", 3);
reply_len = 3; reply_len = 3;
@ -3600,6 +3608,18 @@ static int hostapd_ctrl_iface_receive_process(struct hostapd_data *hapd,
reply_len = 5; reply_len = 5;
} }
#ifdef CONFIG_TESTING_OPTIONS
if (console) {
if (reply_len + 2 >= reply_size)
reply = os_realloc(reply, reply_size + 2);
memmove(reply + 2, reply, reply_len);
reply[0] = '>';
reply[1] = ' ';
reply_len += 2;
}
#endif /* CONFIG_TESTING_OPTIONS */
return reply_len; return reply_len;
} }

View File

@ -19,14 +19,20 @@ def wpaspy_clear_messages(ctrl):
#TODO: Modify so we can ignore other messages over the command interface #TODO: Modify so we can ignore other messages over the command interface
def wpaspy_command(ctrl, cmd): def wpaspy_command(ctrl, cmd):
wpaspy_clear_messages(ctrl) wpaspy_clear_messages(ctrl)
rval = ctrl.request(cmd)
# Include console prefix so we can ignore other messages sent over the control interface
rval = ctrl.request("> " + cmd)
while not rval.startswith("> "):
rval = ctrl.recv()
if "UNKNOWN COMMAND" in rval: if "UNKNOWN COMMAND" in rval:
log(ERROR, "wpa_supplicant did not recognize the command %s. Did you (re)compile wpa_supplicant?" % cmd.split()[0]) log(ERROR, "wpa_supplicant did not recognize the command %s. Did you (re)compile wpa_supplicant?" % cmd.split()[0])
quit(1) quit(1)
elif "FAIL" in rval: elif "FAIL" in rval:
log(ERROR, f"Failed to execute command {cmd}") log(ERROR, f"Failed to execute command {cmd}")
quit(1) quit(1)
return rval
return rval[2:]
def argv_pop_argument(argument): def argv_pop_argument(argument):
if not argument in sys.argv: return False if not argument in sys.argv: return False

View File

@ -10141,6 +10141,14 @@ char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant *wpa_s,
char *reply; char *reply;
const int reply_size = 4096; const int reply_size = 4096;
int reply_len; int reply_len;
int console = 0;
#ifdef CONFIG_TESTING_OPTIONS
if (os_strncmp(buf, "> ", 2) == 0) {
console = 1;
buf += 2;
}
#endif /* CONFIG_TESTING_OPTIONS */
if (os_strncmp(buf, WPA_CTRL_RSP, os_strlen(WPA_CTRL_RSP)) == 0 || if (os_strncmp(buf, WPA_CTRL_RSP, os_strlen(WPA_CTRL_RSP)) == 0 ||
os_strncmp(buf, "SET_NETWORK ", 12) == 0 || os_strncmp(buf, "SET_NETWORK ", 12) == 0 ||
@ -11027,6 +11035,18 @@ char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant *wpa_s,
reply_len = 5; reply_len = 5;
} }
#ifdef CONFIG_TESTING_OPTIONS
if (console) {
if (reply_len + 2 >= reply_size)
reply = os_realloc(reply, reply_size + 2);
memmove(reply + 2, reply, reply_len);
reply[0] = '>';
reply[1] = ' ';
reply_len += 2;
}
#endif /* CONFIG_TESTING_OPTIONS */
*resp_len = reply_len; *resp_len = reply_len;
return reply; return reply;
} }