Skip to content

Force Proxy to any Windows/MacOS/Linux Application TCP and UDP traffic

feat(linux/gui): rule names, DNS via proxy per proxy, Also proxy localhost traffic per rule

anof-cyberd1dcd004cb98
diff --git a/Linux/gui/gui.h b/Linux/gui/gui.h
index 60b58b9..e8ab865 100644
--- a/Linux/gui/gui.h
+++ b/Linux/gui/gui.h
@@ -19,16 +19,19 @@ typedef struct {
uint16_t port;
char *username;
char *password;
+ bool send_domain; // DNS via proxy: the proxy resolves host names (default on, like Windows and macOS)
} ProxyData;
typedef struct {
uint32_t id;
+ char *name; // label, may be empty
char *process_name;
char *target_hosts;
char *target_ports;
RuleProtocol protocol;
RuleAction action;
char *proxy_name; // NULL or "" = default proxy
+ bool localhost; // PROXY rule that also proxies loopback traffic
bool enabled;
bool selected;
} RuleData;
diff --git a/Linux/gui/gui_config.c b/Linux/gui/gui_config.c
index cb295df..aa38715 100644
--- a/Linux/gui/gui_config.c
+++ b/Linux/gui/gui_config.c
@@ -95,11 +95,14 @@ static ProxyData *copy_proxy(const ProxyData *src) {
d->port = src->port;
d->username = g_strdup(src->username ? src->username : "");
d->password = g_strdup(src->password ? src->password : "");
+ d->send_domain = src->send_domain;
return d;
}
static RuleData *copy_rule(const RuleData *src) {
RuleData *d = g_malloc0(sizeof(RuleData));
+ d->name = g_strdup(src->name ? src->name : "");
+ d->localhost = src->localhost;
d->process_name = g_strdup(src->process_name ? src->process_name : "");
d->target_hosts = g_strdup(src->target_hosts ? src->target_hosts : "");
d->target_ports = g_strdup(src->target_ports ? src->target_ports : "");
@@ -195,12 +198,15 @@ static void profile_to_pbp(const Profile *prof, struct pbp_profile *out) {
x->port = p->port;
x->user = p->username ? p->username : (char *)"";
x->pass = p->password ? p->password : (char *)"";
+ x->send_domain = p->send_domain;
if (prof->default_proxy && strcmp(prof->default_proxy, p->name) == 0) out->default_proxy_id = x->id;
}
size_t i = 0;
for (GList *l = prof->rules; l != NULL; l = l->next) {
RuleData *r = (RuleData *)l->data;
struct pbp_rule *x = &out->rules[i++];
+ x->name = r->name ? r->name : (char *)"";
+ x->localhost = r->localhost;
x->process = r->process_name ? r->process_name : (char *)"*";
x->hosts = r->target_hosts ? r->target_hosts : (char *)"*";
x->ports = r->target_ports ? r->target_ports : (char *)"*";
@@ -228,11 +234,14 @@ static void fill_profile_from_pbp(Profile *p, const struct pbp_profile *src) {
px->port = x->port;
px->username = g_strdup(x->user);
px->password = g_strdup(x->pass);
+ px->send_domain = x->send_domain;
p->proxies = g_list_append(p->proxies, px);
}
for (size_t i = 0; i < src->nrules; i++) {
const struct pbp_rule *x = &src->rules[i];
RuleData *r = g_malloc0(sizeof(RuleData));
+ r->name = g_strdup(x->name);
+ r->localhost = x->localhost;
r->process_name = g_strdup(x->process);
r->target_hosts = g_strdup(x->hosts);
r->target_ports = g_strdup(x->ports);
@@ -363,6 +372,7 @@ static ProxyData *parse_proxy_line(char *line) {
px->port = (port >= 1 && port <= 65535) ? (uint16_t)port : 0;
px->username = unesc(n > 4 ? fields[4] : "");
px->password = unesc(n > 5 ? fields[5] : "");
+ px->send_domain = true;
return px;
}
@@ -475,6 +485,7 @@ static bool load_legacy_ini(const char *dir, char **saved_active_out) {
px->port = (uint16_t)old_port;
px->username = g_strdup(old_user);
px->password = g_strdup(old_pass);
+ px->send_domain = true;
d->proxies = g_list_append(d->proxies, px);
g_free(d->default_proxy);
d->default_proxy = g_strdup("default");
diff --git a/Linux/gui/gui_json.c b/Linux/gui/gui_json.c
index 7742949..6111a34 100644
--- a/Linux/gui/gui_json.c
+++ b/Linux/gui/gui_json.c
@@ -96,6 +96,8 @@ int rules_from_json(const char *json, RuleImportCb cb, void *ud) {
cur = end + 1;
RuleData r = {0};
+ r.name = extract_sub_json_str(obj, "name");
+ r.localhost = json_bool(obj, "localhostViaProxy", false);
r.process_name = extract_sub_json_str(obj, "processNames");
r.target_hosts = extract_sub_json_str(obj, "targetHosts");
r.target_ports = extract_sub_json_str(obj, "targetPorts");
@@ -110,7 +112,7 @@ int rules_from_json(const char *json, RuleImportCb cb, void *ud) {
cb(&r, ++count, ud);
- g_free(r.process_name); g_free(r.target_hosts); g_free(r.target_ports); g_free(r.proxy_name);
+ g_free(r.name); g_free(r.process_name); g_free(r.target_hosts); g_free(r.target_ports); g_free(r.proxy_name);
g_free(proto); g_free(act); g_free(obj);
}
return count;
@@ -128,10 +130,12 @@ char *rules_to_json(GList *rules, bool only_selected) {
char *pxy = escape_json_string(r->action == RULE_ACTION_PROXY ? r->proxy_name : NULL);
const char *proto = r->protocol == RULE_PROTOCOL_TCP ? "TCP" : r->protocol == RULE_PROTOCOL_UDP ? "UDP" : "BOTH";
const char *act = r->action == RULE_ACTION_PROXY ? "PROXY" : r->action == RULE_ACTION_DIRECT ? "DIRECT" : "BLOCK";
- g_string_append_printf(out, "%s {\n \"processNames\": \"%s\",\n \"targetHosts\": \"%s\",\n \"targetPorts\": \"%s\",\n"
+ char *nm = escape_json_string(r->name);
+ g_string_append_printf(out, "%s {\n \"name\": \"%s\",\n \"localhostViaProxy\": %s,\n \"processNames\": \"%s\",\n \"targetHosts\": \"%s\",\n \"targetPorts\": \"%s\",\n"
" \"protocol\": \"%s\",\n \"ruleProtocol\": \"%s\",\n \"action\": \"%s\",\n \"ruleAction\": \"%s\",\n"
" \"proxy\": \"%s\",\n \"enabled\": %s\n }",
- first ? "" : ",\n", proc, host, port, proto, proto, act, act, pxy, r->enabled ? "true" : "false");
+ first ? "" : ",\n", nm, r->localhost && r->action == RULE_ACTION_PROXY ? "true" : "false", proc, host, port, proto, proto, act, act, pxy, r->enabled ? "true" : "false");
+ g_free(nm);
g_free(proc); g_free(host); g_free(port); g_free(pxy);
first = false;
}
diff --git a/Linux/gui/gui_rules.c b/Linux/gui/gui_rules.c
index a3b7916..027fd95 100644
--- a/Linux/gui/gui_rules.c
+++ b/Linux/gui/gui_rules.c
@@ -8,6 +8,7 @@ static void refresh_rules_ui();
void free_rule_data(RuleData *rule) {
if (!rule) return;
+ g_free(rule->name);
g_free(rule->process_name);
g_free(rule->target_hosts);
g_free(rule->target_ports);
@@ -38,8 +39,12 @@ void apply_rules_to_lib() {
char err[256] = "";
r->id = ProxyBridge_AddRule(r->process_name, r->target_hosts, r->target_ports, r->protocol, r->action,
rule_proxy_id(r->action, r->proxy_name), err, sizeof(err));
- if (r->id == 0) gui_log("Rule #%d (%s) not loaded: %s", n, r->process_name, err[0] ? err : "rejected");
- else if (!r->enabled) ProxyBridge_DisableRule(r->id);
+ if (r->id == 0) {
+ gui_log("Rule #%d (%s) not loaded: %s", n, r->process_name, err[0] ? err : "rejected");
+ continue;
+ }
+ if (r->localhost && r->action == RULE_ACTION_PROXY) ProxyBridge_SetRuleLocalhost(r->id, true);
+ if (!r->enabled) ProxyBridge_DisableRule(r->id);
}
}
@@ -105,8 +110,8 @@ static void set_str(char **dst, const char *src) {
}
// returns the saved rule, NULL while the engine rejects it (err filled)
-static RuleData *save_rule(RuleData *rule, const char *proc, const char *hosts, const char *ports,
- RuleProtocol proto, RuleAction action, const char *proxy_name, char *err, size_t err_size) {
+static RuleData *save_rule(RuleData *rule, const char *name, const char *proc, const char *hosts, const char *ports,
+ RuleProtocol proto, RuleAction action, const char *proxy_name, bool localhost, char *err, size_t err_size) {
if (!ProxyBridge_ValidateRule(proc, hosts, ports, err, err_size)) return NULL;
uint32_t pid = rule_proxy_id(action, proxy_name);
@@ -125,6 +130,10 @@ static RuleData *save_rule(RuleData *rule, const char *proc, const char *hosts,
rule->id = id;
ProxyBridge_MoveRule(id, lib_index_of(rule));
}
+ localhost = localhost && action == RULE_ACTION_PROXY;
+ ProxyBridge_SetRuleLocalhost(rule->id, localhost);
+ rule->localhost = localhost;
+ set_str(&rule->name, name);
set_str(&rule->process_name, proc);
set_str(&rule->target_hosts, hosts);
set_str(&rule->target_ports, ports);
@@ -186,20 +195,31 @@ static void open_rule_dialog(RuleData *rule) {
gtk_combo_box_set_active(GTK_COMBO_BOX(proto_combo), rule ? (int)rule->protocol : RULE_PROTOCOL_BOTH);
gtk_combo_box_set_active(GTK_COMBO_BOX(action_combo), rule ? (int)rule->action : RULE_ACTION_PROXY);
+ GtkWidget *name_entry = gtk_entry_new();
+ gtk_entry_set_max_length(GTK_ENTRY(name_entry), 127);
+ gtk_entry_set_text(GTK_ENTRY(name_entry), rule && rule->name ? rule->name : "");
+ GtkWidget *localhost_check = gtk_check_button_new_with_label("Also proxy localhost traffic (127.0.0.0/8 and ::1)");
+ gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(localhost_check), rule && rule->localhost);
+ g_signal_connect(action_combo, "changed", G_CALLBACK(on_action_changed), localhost_check);
+
GtkWidget *err_label = hint_label("");
- grid_row(grid, 0, "Process Name:", proc_box);
- gtk_grid_attach(GTK_GRID(grid), hint_label("Example: firefox; chrome; /usr/bin/wget"), 1, 1, 1, 1);
- grid_row(grid, 2, "Target Host:", host_entry);
- gtk_grid_attach(GTK_GRID(grid), hint_label("Example: 192.168.1.*; 10.0.0.0/8; 10.0.0.1-10.0.0.50; github.com; *.github.com; * (domains are matched via DNS answers). Long lists are fine; line breaks are for readability only, separate entries with ;"), 1, 3, 1, 1);
- grid_row(grid, 4, "Target Port:", port_entry);
- gtk_grid_attach(GTK_GRID(grid), hint_label("Example: 80; 443; 8000-8080; *"), 1, 5, 1, 1);
- grid_row(grid, 6, "Protocol:", proto_combo);
- grid_row(grid, 7, "Action:", action_combo);
- grid_row(grid, 8, "Proxy:", proxy_combo);
- gtk_grid_attach(GTK_GRID(grid), err_label, 0, 9, 2, 1);
+ grid_row(grid, 0, "Name:", name_entry);
+ grid_row(grid, 1, "Process Name:", proc_box);
+ gtk_grid_attach(GTK_GRID(grid), hint_label("Example: firefox; chrome; /usr/bin/wget"), 1, 2, 1, 1);
+ grid_row(grid, 3, "Target Host:", host_entry);
+ gtk_grid_attach(GTK_GRID(grid), hint_label("Example: 192.168.1.*; 10.0.0.0/8; 10.0.0.1-10.0.0.50; github.com; *.github.com; * (domains are matched via DNS answers). Long lists are fine; line breaks are for readability only, separate entries with ;"), 1, 4, 1, 1);
+ grid_row(grid, 5, "Target Port:", port_entry);
+ gtk_grid_attach(GTK_GRID(grid), hint_label("Example: 80; 443; 8000-8080; *"), 1, 6, 1, 1);
+ grid_row(grid, 7, "Protocol:", proto_combo);
+ grid_row(grid, 8, "Action:", action_combo);
+ grid_row(grid, 9, "Proxy:", proxy_combo);
+ gtk_grid_attach(GTK_GRID(grid), localhost_check, 1, 10, 1, 1);
+ gtk_grid_attach(GTK_GRID(grid), hint_label("Without this, a PROXY rule leaves connections to this computer (localhost) direct. DNS to a local resolver is never proxied."), 1, 11, 1, 1);
+ gtk_grid_attach(GTK_GRID(grid), err_label, 0, 12, 2, 1);
gtk_container_add(GTK_CONTAINER(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), grid);
gtk_widget_show_all(dialog);
on_action_changed(GTK_COMBO_BOX(action_combo), proxy_combo);
+ on_action_changed(GTK_COMBO_BOX(action_combo), localhost_check);
bool saved = false;
while (!saved && gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
@@ -216,9 +236,10 @@ static void open_rule_dialog(RuleData *rule) {
char *clean_hosts = list_normalize(raw_hosts);
g_free(raw_hosts);
- saved = save_rule(rule, gtk_entry_get_text(GTK_ENTRY(proc_entry)), clean_hosts,
+ saved = save_rule(rule, gtk_entry_get_text(GTK_ENTRY(name_entry)), gtk_entry_get_text(GTK_ENTRY(proc_entry)), clean_hosts,
gtk_entry_get_text(GTK_ENTRY(port_entry)), proto < 0 ? RULE_PROTOCOL_BOTH : (RuleProtocol)proto,
- action < 0 ? RULE_ACTION_PROXY : (RuleAction)action, pd ? pd->name : NULL, err, sizeof(err)) != NULL;
+ action < 0 ? RULE_ACTION_PROXY : (RuleAction)action, pd ? pd->name : NULL,
+ gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(localhost_check)), err, sizeof(err)) != NULL;
g_free(clean_hosts);
if (saved) {
save_config();
@@ -300,9 +321,12 @@ static void import_rule_cb(const RuleData *r, int index, void *ud) {
!r->process_name ? "missing processNames" : err[0] ? err : "rejected");
return;
}
+ if (r->localhost && r->action == RULE_ACTION_PROXY) ProxyBridge_SetRuleLocalhost(id, true);
if (!r->enabled) ProxyBridge_DisableRule(id);
RuleData *nd = g_malloc0(sizeof(RuleData));
nd->id = id;
+ nd->name = g_strdup(r->name ? r->name : "");
+ nd->localhost = r->localhost && r->action == RULE_ACTION_PROXY;
nd->process_name = g_strdup(r->process_name);
nd->target_hosts = g_strdup(r->target_hosts);
nd->target_ports = g_strdup(r->target_ports);
@@ -406,10 +430,10 @@ static void refresh_rules_ui() {
gtk_grid_set_column_spacing(GTK_GRID(grid), 15);
gtk_container_add(GTK_CONTAINER(rules_list_box), grid);
- const char *heads[] = {" ", "Enable", "Actions", "SR", "Process", "Target Hosts", "Protocol", "Action", "Proxy"};
- for (int c = 0; c < 9; c++)
- gtk_grid_attach(GTK_GRID(grid), header_label(heads[c], c == 4 || c == 5), c, 0, 1, 1);
- gtk_grid_attach(GTK_GRID(grid), gtk_separator_new(GTK_ORIENTATION_HORIZONTAL), 0, 1, 9, 1);
+ const char *heads[] = {" ", "Enable", "Actions", "SR", "Name", "Process", "Target Hosts", "Protocol", "Action", "Proxy"};
+ for (int c = 0; c < 10; c++)
+ gtk_grid_attach(GTK_GRID(grid), header_label(heads[c], c == 5 || c == 6), c, 0, 1, 1);
+ gtk_grid_attach(GTK_GRID(grid), gtk_separator_new(GTK_ORIENTATION_HORIZONTAL), 0, 1, 10, 1);
const char *proto_strs[] = {"TCP", "UDP", "BOTH"};
const char *action_strs[] = {"PROXY", "DIRECT", "BLOCK"};
@@ -431,20 +455,23 @@ static void refresh_rules_ui() {
char sr_str[16];
snprintf(sr_str, sizeof(sr_str), "%d", sr++);
gtk_grid_attach(GTK_GRID(grid), gtk_label_new(sr_str), 3, row, 1, 1);
- gtk_grid_attach(GTK_GRID(grid), cell_label(r->process_name), 4, row, 1, 1);
- gtk_grid_attach(GTK_GRID(grid), cell_label(r->target_hosts), 5, row, 1, 1);
- gtk_grid_attach(GTK_GRID(grid), gtk_label_new(proto_strs[r->protocol <= RULE_PROTOCOL_BOTH ? r->protocol : RULE_PROTOCOL_BOTH]), 6, row, 1, 1);
+ gtk_grid_attach(GTK_GRID(grid), cell_label(r->name && *r->name ? r->name : "-"), 4, row, 1, 1);
+ gtk_grid_attach(GTK_GRID(grid), cell_label(r->process_name), 5, row, 1, 1);
+ gtk_grid_attach(GTK_GRID(grid), cell_label(r->target_hosts), 6, row, 1, 1);
+ gtk_grid_attach(GTK_GRID(grid), gtk_label_new(proto_strs[r->protocol <= RULE_PROTOCOL_BOTH ? r->protocol : RULE_PROTOCOL_BOTH]), 7, row, 1, 1);
int a = r->action <= RULE_ACTION_BLOCK ? r->action : RULE_ACTION_PROXY;
GtkWidget *l_act = gtk_label_new(action_strs[a]);
gtk_style_context_add_class(gtk_widget_get_style_context(l_act), action_class[a]);
- gtk_grid_attach(GTK_GRID(grid), l_act, 7, row, 1, 1);
+ gtk_grid_attach(GTK_GRID(grid), l_act, 8, row, 1, 1);
const char *proxy_txt = "-";
if (r->action == RULE_ACTION_PROXY)
proxy_txt = (r->proxy_name && find_proxy_by_name(r->proxy_name)) ? r->proxy_name : "default";
- gtk_grid_attach(GTK_GRID(grid), cell_label(proxy_txt), 8, row, 1, 1);
- gtk_grid_attach(GTK_GRID(grid), gtk_separator_new(GTK_ORIENTATION_HORIZONTAL), 0, row + 1, 9, 1);
+ char *proxy_cell = g_strdup_printf("%s%s", proxy_txt, r->localhost ? " (+localhost)" : "");
+ gtk_grid_attach(GTK_GRID(grid), cell_label(proxy_cell), 9, row, 1, 1);
+ g_free(proxy_cell);
+ gtk_grid_attach(GTK_GRID(grid), gtk_separator_new(GTK_ORIENTATION_HORIZONTAL), 0, row + 1, 10, 1);
}
gtk_widget_show_all(rules_list_box);
}
diff --git a/Linux/gui/gui_settings.c b/Linux/gui/gui_settings.c
index cbf9912..bc1cf46 100644
--- a/Linux/gui/gui_settings.c
+++ b/Linux/gui/gui_settings.c
@@ -57,6 +57,7 @@ void apply_proxies_to_lib() {
char err[256] = "";
p->id = ProxyBridge_AddProxy(p->name, p->type, p->host, p->port, p->username, p->password, err, sizeof(err));
if (p->id == 0) gui_log("Proxy '%s' rejected: %s", p->name, err[0] ? err : "unknown error");
+ else if (!p->send_domain) ProxyBridge_SetProxySendDomain(p->id, false);
}
ProxyBridge_SetDefaultProxy(resolve_proxy_id(g_default_proxy));
}
@@ -211,8 +212,12 @@ static ProxyData *proxy_edit_dialog(GtkWindow *parent, ProxyData *existing) {
grid_row(grid, 3, "Port:", port_entry);
grid_row(grid, 4, "Username:", user_entry);
grid_row(grid, 5, "Password:", pass_entry);
+ GtkWidget *dns_check = gtk_check_button_new_with_label("DNS via proxy (the proxy resolves host names)");
+ gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(dns_check), existing ? existing->send_domain : TRUE);
+ gtk_grid_attach(GTK_GRID(grid), dns_check, 1, 6, 1, 1);
+ gtk_grid_attach(GTK_GRID(grid), hint_label("On: connections to a name the application resolved are sent to the proxy by name. Off: the IP address is sent. UDP always uses the IP."), 1, 7, 1, 1);
GtkWidget *err_label = hint_label("");
- gtk_grid_attach(GTK_GRID(grid), err_label, 0, 6, 2, 1);
+ gtk_grid_attach(GTK_GRID(grid), err_label, 0, 8, 2, 1);
gtk_combo_box_set_active(GTK_COMBO_BOX(type_combo), 1);
if (existing) {
@@ -255,7 +260,8 @@ static ProxyData *proxy_edit_dialog(GtkWindow *parent, ProxyData *existing) {
id = ProxyBridge_AddProxy(name, type, host, (uint16_t)port, user, pass, err, sizeof(err));
ok = id != 0;
}
- if (!ok) msg = err[0] ? err : "Engine rejected the proxy settings.";
+ if (ok) ProxyBridge_SetProxySendDomain(id, gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(dns_check)));
+ else msg = err[0] ? err : "Engine rejected the proxy settings.";
}
if (msg) {
set_error_label(err_label, msg);
@@ -279,6 +285,7 @@ static ProxyData *proxy_edit_dialog(GtkWindow *parent, ProxyData *existing) {
set_str(&p->password, pass);
p->type = type;
p->port = (uint16_t)port;
+ p->send_domain = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(dns_check));
if (!find_proxy_by_name(g_default_proxy)) {
set_str(&g_default_proxy, p->name);
diff --git a/Linux/gui/tests/config_test.c b/Linux/gui/tests/config_test.c
index 1c251c1..1973700 100644
--- a/Linux/gui/tests/config_test.c
+++ b/Linux/gui/tests/config_test.c
@@ -16,7 +16,7 @@ void free_proxy_data(ProxyData *p) {
}
void free_rule_data(RuleData *r) {
- g_free(r->process_name); g_free(r->target_hosts); g_free(r->target_ports); g_free(r->proxy_name); g_free(r);
+ g_free(r->name); g_free(r->process_name); g_free(r->target_hosts); g_free(r->target_ports); g_free(r->proxy_name); g_free(r);
}
static int failures = 0;
@@ -37,12 +37,14 @@ static void add_content(const char *proxy_name) {
ProxyData *px = g_malloc0(sizeof(ProxyData));
px->name = g_strdup(proxy_name); px->host = g_strdup("github.com"); px->port = 8080;
px->username = g_strdup(""); px->password = g_strdup("s3cr|et");
+ px->send_domain = false;
g_proxies_list = g_list_append(g_proxies_list, px);
g_free(g_default_proxy);
g_default_proxy = g_strdup(proxy_name);
RuleData *r = g_malloc0(sizeof(RuleData));
r->process_name = g_strdup("curl"); r->target_hosts = g_strdup("*.github.com"); r->target_ports = g_strdup("*");
r->action = RULE_ACTION_PROXY; r->proxy_name = g_strdup(proxy_name); r->enabled = true;
+ r->name = g_strdup("Burp \"intercept\""); r->localhost = true;
g_rules_list = g_list_append(g_rules_list, r);
}
@@ -203,6 +205,8 @@ int main() {
CHECK(strcmp(((ProxyData *)g_proxies_list->data)->name, "p 1|x") == 0);
CHECK(strcmp(((ProxyData *)g_proxies_list->data)->password, "s3cr|et") == 0);
CHECK(strcmp(((RuleData *)g_rules_list->data)->target_hosts, "*.github.com") == 0);
+ CHECK(!((ProxyData *)g_proxies_list->data)->send_domain); // per-proxy "DNS via proxy" survives a restart
+ CHECK(strcmp(((RuleData *)g_rules_list->data)->name, "Burp \"intercept\"") == 0 && ((RuleData *)g_rules_list->data)->localhost);
CHECK(!g_chk_dns && !g_chk_logging); // restored from the Work profile file itself
CHECK(profile_find("Home") && !profile_find("Home")->logging && profile_find("Home")->dns); // migrated values of the old file, per profile
CHECK(profile_find("Home") && g_list_length(profile_find("Home")->rules) == 1);
diff --git a/Linux/tests/gui_headless.sh b/Linux/tests/gui_headless.sh
index 7db459a..1d4cb84 100755
--- a/Linux/tests/gui_headless.sh
+++ b/Linux/tests/gui_headless.sh
@@ -11,7 +11,7 @@ PASS=0; FAIL=0; DNSIP=10.77.0.4
ok() { echo " PASS $1"; PASS=$((PASS+1)); }
bad() { echo " FAIL $1"; FAIL=$((FAIL+1)); }
has() { [[ "$2" == *"$3"* ]] && ok "$1" || bad "$1 (got: ${2:0:160})"; }
-cleanup() { kill $GUI_PID $FAKE $DNSP $BW 2>/dev/null; wait 2>/dev/null; ip addr del $DNSIP/32 dev lo 2>/dev/null; rm -rf "$WORK"; }
+cleanup() { kill $GUI_PID $FAKE $DNSP $BW $WWW 2>/dev/null; wait 2>/dev/null; ip addr del $DNSIP/32 dev lo 2>/dev/null; rm -rf "$WORK"; }
trap cleanup EXIT
[ "$(id -u)" = 0 ] || { echo "run as root"; exit 1; }
ip addr add $DNSIP/32 dev lo 2>/dev/null
@@ -72,7 +72,7 @@ out=$(curl -s -m 5 http://198.51.100.7/); has "rule 2: curl -> proxy b (with
out=$(curl -s -m 5 http://203.0.114.7/ 2>&1; echo "rc=$?"); has "rule 3: BLOCK" "$out" "rc=7"
out=$(curl -s -m 2 http://203.0.113.7/ 2>&1; echo "rc=$?"); [[ "$out" != *hello-from* ]] && ok "disabled rule 5 is not applied" || bad "disabled rule applied"
ip4=$(dig @$DNSIP app.example.test +short +time=3 +tries=1 | head -1)
-out=$(curl -s -m 5 http://$ip4/); has "domain rule from the config (*.example.test -> b) after a real DNS lookup" "$out" "hello-from-B dst=192.0.2.77:80"
+out=$(curl -s -m 5 http://$ip4/); has "domain rule from the config (*.example.test -> b) after a real DNS lookup" "$out" "hello-from-B dst=app.example.test:80"
stop_gui
"${BPFTOOL:-bpftool}" prog show 2>/dev/null | grep -q pb_connect && bad "BPF programs left after GUI exit" || ok "programs detached after GUI exit"
@@ -96,11 +96,19 @@ echo "== a profile exported by the Windows app, dropped into the profiles direct
cat > "$P/From Windows.pbprofile" <<'JSON'
{ "Version": "1.0", "LocalhostViaProxy": false, "IsTrafficLoggingEnabled": true,
"ProxyConfigs": [ { "Id": 5, "Type": "socks5", "Host": "127.0.0.1", "Port": "19080", "Username": "", "Password": "", "SendDomainToProxy": true } ],
- "ProxyRules": [ { "ProcessName": "curl", "TargetHosts": "192.0.2.0/24", "TargetPorts": "*", "TargetDomains": "", "Protocol": "TCP", "Action": "PROXY", "IsEnabled": true, "ProxyConfigId": 5 } ] }
+ "ProxyRules": [
+ { "ProcessName": "curl", "TargetHosts": "192.0.2.0/24", "TargetPorts": "*", "TargetDomains": "", "Protocol": "TCP", "Action": "PROXY", "IsEnabled": true, "ProxyConfigId": 5 },
+ { "Name": "Burp intercept", "ProcessName": "curl", "TargetHosts": "127.0.0.1", "TargetPorts": "18401", "Protocol": "TCP", "Action": "PROXY", "IsEnabled": true, "ProxyConfigId": 5, "LocalhostViaProxy": true } ] }
JSON
+mkdir -p "$WORK/www"; echo local-origin > "$WORK/www/index.html"
+python3 -m http.server 18401 --bind 127.0.0.1 --directory "$WORK/www" >/dev/null 2>&1 & WWW=$!
+sleep 0.5
run_gui "From Windows"
out=$(curl -s -m 5 http://192.0.2.9/); has "rule and proxy imported from the Windows file are applied" "$out" "hello-from-A dst=192.0.2.9:80"
+out=$(curl -s -m 5 http://127.0.0.1:18401/); has "per-rule LocalhostViaProxy from the Windows file is applied" "$out" "hello-from-A dst=127.0.0.1:18401"
stop_gui
+grep -q '"Name": "Burp intercept"' "$P/From Windows.pbprofile" && grep -q '"LocalhostViaProxy": true' "$P/From Windows.pbprofile" && grep -q '"SendDomainToProxy": true' "$P/From Windows.pbprofile" \
+ && ok "rule name, localhost flag and DNS-via-proxy survive the GUI saving the profile" || bad "fields lost: $(cat "$P/From Windows.pbprofile")"
out=$(PROXYBRIDGE_CONFIG_DIR="$WORK/cfg" LD_LIBRARY_PATH="$LIBDIR" "$LIBDIR/ProxyBridge" --list-profiles 2>&1)
has "the CLI lists the GUI's profiles" "$out" "From Windows"
[ "$(stat -c %a "$P/From Windows.pbprofile")" = 600 ] && ok "the dropped-in file was tightened to 0600" || bad "dropped-in file mode"