@@ -16,3 +16,128 @@ defmodule Ex do
16
16
:world
17
17
end
18
18
end
19
+
20
+ defmodule Snip do
21
+ def trim_elixir ( mod ) when is_list ( mod ) do
22
+ Enum . map ( mod , & String . to_atom ( String . trim ( "#{ & 1 } " , "Elixir." ) ) )
23
+ end
24
+
25
+ def trim_elixir ( mod ) do
26
+ String . to_atom ( String . trim ( "#{ mod } " , "Elixir." ) )
27
+ end
28
+
29
+ defmodule Locallink do
30
+ def route ( _ , source , dest , dest_port ) do
31
+ IO . inspect ( { :route , source , dest , dest_port } )
32
+
33
+ case { source , dest , dest_port } do
34
+ # {_, _, 80} -> %{uplink: nil, module: Mitm.Hexdump} #master server
35
+ # master server
36
+ { _ , _ , 33004 } -> % { uplink: nil , module: Mitm.Lobby }
37
+ # game server
38
+ { _ , _ , 35001 } -> % { uplink: nil , module: Mitm.Game }
39
+ _ -> % { module: Raw , uplink: nil }
40
+ end
41
+ end
42
+ end
43
+
44
+ defmodule S5link do
45
+ def route ( _ , source , dest , dest_port ) do
46
+ if dest_port != 443 do
47
+ IO . inspect ( { :route , source , dest , dest_port } )
48
+ end
49
+
50
+ case { source , dest , dest_port } do
51
+ # master server
52
+ { _ , _ , p } when p in [ 30204 , 20000 , 10000 , 4000 ] ->
53
+ % { uplink: nil , module: Mitm.Proto }
54
+
55
+ # {_, _, _} ->
56
+ # proxy = %{
57
+ # host: "http://49.0.246.161:3344",
58
+ # ip: "49.0.246.161",
59
+ # password: "aa1111",
60
+ # port: 3344,
61
+ # type: :socks5,
62
+ # username: "aa1111"
63
+ # }
64
+ #
65
+ # %{uplink: proxy, module: Raw }
66
+
67
+ _ ->
68
+ % { module: Raw , uplink: nil }
69
+ end
70
+ end
71
+ end
72
+
73
+ def locallink ( router \\ Snip.S5link ) do
74
+ specs = [
75
+ % { port: 31332 , router: router } ,
76
+ % { port: 9021 , router: router , listener_type: :sock5 }
77
+ ]
78
+
79
+ # DNS.Server2Sup.start_link(%{
80
+ # static_names: %{"live-dl.nightcrows.com" => {172, 0, 0, 1}},
81
+ # uplink_server: "1.1.1.1",
82
+ # proxy: {"127.0.0.1", 1080}
83
+ # })
84
+
85
+ # {:ok, _} = DynamicSupervisor.start_child(NC.Supervisor, %{
86
+ # id: MitmConns,
87
+ # start: {Mitme.Acceptor.Supervisor, :start_link, [[locallink]]}})
88
+ { :ok , _ } = Mitme.Acceptor.Supervisor . start_link ( specs )
89
+ end
90
+
91
+ def link_s5 ( specs \\ % { port: 9021 , router: Snip.S5link , listener_type: :sock5 } ) do
92
+ # {:ok, _} = DynamicSupervisor.start_child(NC.Supervisor, %{
93
+ # id: MitmConns,
94
+ # start: {Mitme.Acceptor.Supervisor, :start_link, [[locallink]]}})
95
+
96
+ # DNS.Server2Sup.start_link(
97
+ # %{
98
+ # static_names: %{"live-dl.nightcrows.co.kr" => "172.0.0.1"},
99
+ # uplink_server: "1.1.1.1",
100
+ # proxy: {"192.168.2.153", 1080}
101
+ # },
102
+ # max_restarts: 99999999999
103
+ # )
104
+
105
+ { :ok , _ } = Mitme.Acceptor.Supervisor . start_link ( [ specs ] )
106
+ end
107
+ end
108
+
109
+ defmodule Mitm.Hexdump2 do
110
+ use GenServer
111
+
112
+ def init ( _ ) do
113
+ { :ok , % { } }
114
+ end
115
+
116
+ def connect_addr ( address , port ) do
117
+ IO . inspect ( { :connect , address , port } )
118
+ { address , port }
119
+ end
120
+
121
+ def on_connect ( flow = % { dest: socket } ) do
122
+ :inet . setopts ( socket , [ { :active , true } , :binary ] )
123
+ Map . merge ( flow , % { start_time: :os . system_time ( 1 ) } )
124
+ end
125
+
126
+ def on_close ( socket , state ) do
127
+ state
128
+ end
129
+
130
+ # server conn
131
+ def proc_packet ( :server , bin , s ) do
132
+ IO . puts ( "<- #{ s . dest_addr } #{ s . dest_port } " )
133
+ IO . puts ( Hexdump . to_string ( bin ) )
134
+ { :send , bin , s }
135
+ end
136
+
137
+ # client conn
138
+ def proc_packet ( :client , bin , s ) do
139
+ IO . puts ( "-> #{ s . dest_addr } #{ s . dest_port } " )
140
+ IO . puts ( Hexdump . to_string ( bin ) )
141
+ { :send , bin , s }
142
+ end
143
+ end
0 commit comments