-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
101 lines (85 loc) · 2.93 KB
/
Makefile
File metadata and controls
101 lines (85 loc) · 2.93 KB
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
.PHONY: start stop shutdown stop-server quit-zap restart clean
PAC_PORT ?= 8888
NETWORK ?= Wi-Fi
PROXY_HOST ?= 127.0.0.1
PROXY_PORT ?= 8088
PROXY_ADDRESS := $(PROXY_HOST):$(PROXY_PORT)
SESSION ?= $(CURDIR)/app_debugging
OWASP_ZAP := /Applications/ZAP.app
RUN_ZAP_COMMAND := open $(OWASP_ZAP) --args
RUNNING_ZAP := ps -Ao pid=,command= | awk -v zapcmd=$(OWASP_ZAP) '$$0 ~ zapcmd && $$2 != "awk" {print $$1;exit}'
# Start a new session or use existing session
ifneq "$(wildcard $(SESSION))" ""
# Given session is an existing file
RUN_ZAP_COMMAND += -session "$(abspath $(SESSION))"
else
# Try session with given name in current directory
SESSION_PATH = $(abspath $(SESSION).session)
ifeq "$(wildcard $(SESSION_PATH))" ""
RUN_ZAP_COMMAND += -newsession "$(SESSION_PATH)"
else
RUN_ZAP_COMMAND += -session "$(SESSION_PATH)"
endif
endif
SPECIFIED := environment, command line
ifneq "$(findstring $(origin PROXY_HOST), $(SPECIFIED))" ""
RUN_ZAP_COMMAND += -host $(PROXY_HOST)
endif
ifneq "$(findstring $(origin PROXY_PORT), $(SPECIFIED))" ""
RUN_ZAP_COMMAND += -port $(PROXY_PORT)
endif
start: server.pid zap.pid
shutdown: stop quit-zap stop-server
stop:
@networksetup -setautoproxystate "$(NETWORK)" off
stop-server:
@if test -f server.pid; then \
read PID<server.pid; \
kill $$PID 2>/dev/null && rm server.pid || echo "Failed to stop server (pid = $$PID)" >&2; \
fi; unset -v PID
quit-zap:
@if test -f zap.pid; then \
read PID<zap.pid; rm zap.pid; \
kill $$PID 2>/dev/null || echo "Failed to close ZAP (pid = $$PID)" >&2; \
PID=`$(RUNNING_ZAP)`; \
if test $$PID && test $$PID != $$$$; then \
echo "Trying again with running ZAP (pid = $$PID)" >&2; \
kill $$PID 2>/dev/null; \
fi; \
else \
PID=`$(RUNNING_ZAP)`; \
test $$PID && test $$PID != $$$$ && kill $$PID 2>/dev/null; \
fi; unset -v PID
restart: shutdown start
clean: shutdown
@rm debugging.pac
debugging.pac: urls.conf
@{ \
echo "const hostsToIntercept = ["; \
while read url; do \
echo " '$$url',"; \
done <urls.conf; \
echo "];"; \
echo "function FindProxyForURL(url, host) {"; \
echo " return hostsToIntercept.includes(host) ?"; \
echo " 'PROXY $(PROXY_ADDRESS)' : 'DIRECT';"; \
echo "}"; \
} >debugging.pac
urls.conf:
@echo "Enter url patterns to proxy (leave out scheme; * can be used as a wildcard),\n\
one entry per line, terminating with a blank line:"
@while read -r url && test "$${url}"; do echo "$${url}" >> urls.conf; done
zap.pid: .FORCE
@PID=`$(RUNNING_ZAP)`; \
if test $$PID != $$$$; then \
if test ! -f zap.pid || test $$PID != $$(<zap.pid); then \
echo "ZAP is already running. Updating pid to $$PID"; \
echo $$PID > zap.pid; \
fi; unset -v PID; \
else \
$(RUN_ZAP_COMMAND) && $(RUNNING_ZAP) > zap.pid; \
fi
server.pid: debugging.pac
@python3 -m http.server $(PAC_PORT) --bind 127.0.0.1 2>/dev/null & echo $$! > server.pid
@networksetup -setautoproxyurl "$(NETWORK)" http://127.0.0.1:$(PAC_PORT)/debugging.pac
.FORCE: