Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
R
rt2-adv
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
rt2-adv
Commits
71b57491
Commit
71b57491
authored
Jun 10, 2022
by
Ahmad Nemati
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
init
parent
cb39db69
Pipeline
#149
canceled with stages
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
141 additions
and
6 deletions
+141
-6
app.js
app.js
+132
-6
test_parse
test_parse
+0
-0
test_shell.js
test_shell.js
+9
-0
No files found.
app.js
View file @
71b57491
...
...
@@ -9,6 +9,9 @@ const shellExec = require('shell-exec')
var
decimalPointRegex
=
/
\-?\d
+
\.\d
+/g
;
let
fs
=
require
(
'
fs
'
)
let
port
=
5
let
secret
=
'
0
'
let
domain
=
'
0
'
let
combineSecret
=
''
let
countReboot
=
4
...
...
@@ -61,13 +64,25 @@ async function run() {
let
whiteIp
=
await
getWhiteIp
()
doIptable
(
whiteIp
)
let
portRes
=
await
getPort
()
portRes
=
parseInt
(
portRes
)
portRes
=
parseInt
(
portRes
.
port
)
console
.
log
(
portRes
)
if
(
portRes
===
0
||
portRes
===
443
||
portRes
===
5
)
if
(
portRes
===
0
||
portRes
===
443
||
portRes
===
5
)
{
port
=
randomInt
(
4000
,
60000
)
else
port
=
parseInt
(
portRes
)
let
a
=
await
shell
.
exec
(
'
cd .. && cd mt && sudo ./server1.sh
'
+
port
,
{
silent
:
true
}).
stdout
;
secret
=
await
shellExec
(
'
head -c 16 /dev/urandom | xxd -ps
'
)
secret
=
secret
.
stdout
.
replace
(
'
\n
'
,
''
)
domain
=
makedomain
()
combineSecret
=
getTlsSecret
(
domain
,
secret
)
}
else
{
port
=
parseInt
(
portRes
.
port
)
combineSecret
=
portRes
.
secret
let
d
=
parse
(
combineSecret
)
domain
=
d
.
domain
secret
=
d
.
secret
}
let
a
=
await
shell
.
exec
(
'
cd .. && cd mt && sudo ./server1.sh
'
+
port
+
'
'
+
domain
+
'
'
+
secret
,
{
silent
:
true
}).
stdout
;
console
.
log
(
'
Reset Proxy
'
)
}
...
...
@@ -175,7 +190,7 @@ function sendRate(rx, tx) {
function
getPort
()
{
const
request
=
require
(
'
request
'
);
let
url
=
'
http://23.88.33.146:3000/getPort
'
let
url
=
'
http://23.88.33.146:3000/getPort
Adv2
'
return
new
Promise
(
function
(
resolve
,
reject
)
{
request
(
url
,
{
timeout
:
15000
},
function
(
error
,
res
,
body
)
{
resolve
(
body
)
...
...
@@ -204,3 +219,114 @@ cronSpeed.schedule(' */5 * * * * *', () => {
});
function
getTlsSecret
(
domain
,
secret
)
{
var
domain_bytes
=
Array
.
from
(
domain
).
map
(
(
c
)
=>
c
.
charCodeAt
(
0
)
);
var
tls_bytes
=
hexToBytes
(
"
ee
"
+
secret
).
concat
(
domain_bytes
);
return
encodeURIComponent
(
bytesToHex
(
tls_bytes
))
}
function
parse
(
url
)
{
url
=
'
https://t.me/proxy?server=168.119.96.20&port=443&secret=
'
+
url
var
p
=
url
.
split
(
"
://
"
);
var
proto
=
p
[
0
];
if
(
!
(
proto
==
"
tg
"
||
proto
==
"
https
"
))
{
alert
(
"
invalid URL protocol:
"
+
proto
);
return
false
};
p
=
p
[
1
].
split
(
"
?
"
);
var
host_or_path
=
p
[
0
];
if
(
proto
==
"
tg
"
&&
host_or_path
!=
"
proxy
"
)
{
alert
(
"
invalid path:
"
+
host_or_path
);
return
false
}
else
if
(
proto
==
"
https
"
&&
host_or_path
!=
"
t.me/proxy
"
)
{
alert
(
"
invalid path:
"
+
host_or_path
);
return
false
}
var
query
=
parseQuery
(
p
[
1
]);
var
missing
=
[
"
server
"
,
"
port
"
,
"
secret
"
].
filter
(
(
field
)
=>
!
query
.
hasOwnProperty
(
field
));
if
(
missing
.
length
)
{
alert
(
"
Missing:
"
+
missing
);
return
false
}
var
s
=
query
.
secret
;
var
hex_secret
,
protocol
,
tls_domain
=
""
;
if
(
s
.
length
==
32
&&
is_hex
(
s
))
{
protocol
=
"
Normal
"
;
hex_secret
=
s
}
else
if
(
s
.
length
==
34
&&
s
.
startsWith
(
"
dd
"
)
&&
is_hex
(
s
))
{
protocol
=
"
Secure
"
;
hex_secret
=
s
.
slice
(
-
32
)
}
else
if
(
s
.
length
>
34
&&
s
.
startsWith
(
"
ee
"
)
&&
is_hex
(
s
))
{
protocol
=
"
Fake-TLS, hex secret
"
;
hex_secret
=
s
.
slice
(
2
,
34
);
tls_domain
=
String
.
fromCharCode
.
apply
(
null
,
hexToBytes
(
s
.
slice
(
34
)))
}
else
if
(
s
.
startsWith
(
"
7
"
))
{
protocol
=
"
Fake-TLS
"
;
var
bin_secret
;
if
(
/^
[
0-9a-zA-Z_=-
]
+$/
.
test
(
s
))
{
// urlsafe base64
bin_secret
=
urlSafeBase64ToBytes
(
s
)
protocol
+=
"
, URL-safe base64 secret
"
}
else
if
(
/^
[
0-9a-zA-Z
\+\/
=
]
+$/
.
test
(
s
))
{
// normal base64
bin_secret
=
base64ToBytes
(
s
)
protocol
+=
"
, base64 sectet
"
}
else
{
alert
(
"
Invalid secret:
"
+
s
);
return
false
}
hex_secret
=
bytesToHex
(
Array
.
from
(
bin_secret
.
slice
(
1
,
17
),
c
=>
c
.
charCodeAt
(
0
)));
tls_domain
=
bin_secret
.
slice
(
17
)
}
else
{
alert
(
"
Invalid secret:
"
+
s
)
}
return
{
protocol
:
protocol
,
server
:
query
.
server
,
port
:
query
.
port
,
secret
:
hex_secret
,
domain
:
tls_domain
}
}
function
parseQuery
(
queryString
)
{
var
query
=
{};
var
pairs
=
queryString
.
split
(
'
&
'
);
for
(
var
i
=
0
;
i
<
pairs
.
length
;
i
++
)
{
var
pair
=
pairs
[
i
].
split
(
'
=
'
);
query
[
decodeURIComponent
(
pair
[
0
])]
=
decodeURIComponent
(
pair
[
1
]
||
''
);
}
return
query
;
}
function
base64ToBytes
(
str
)
{
return
atob
(
str
);
}
function
bytesToHex
(
bytes
)
{
for
(
var
hex
=
[],
i
=
0
;
i
<
bytes
.
length
;
i
++
)
{
var
current
=
bytes
[
i
]
<
0
?
bytes
[
i
]
+
256
:
bytes
[
i
];
hex
.
push
((
current
>>>
4
).
toString
(
16
));
hex
.
push
((
current
&
0xF
).
toString
(
16
));
}
return
hex
.
join
(
""
);
}
function
hexToBytes
(
hex
)
{
for
(
var
bytes
=
[],
c
=
0
;
c
<
hex
.
length
;
c
+=
2
)
bytes
.
push
(
parseInt
(
hex
.
substr
(
c
,
2
),
16
));
return
bytes
;
}
function
makedomain
()
{
let
length
=
randomInt
(
5
,
8
)
var
result
=
''
;
var
characters
=
'
abcdefghijklmnopqrstuvwxyz
'
;
var
charactersLength
=
characters
.
length
;
for
(
var
i
=
0
;
i
<
length
;
i
++
)
{
result
+=
characters
.
charAt
(
Math
.
floor
(
Math
.
random
()
*
charactersLength
));
}
return
result
+
'
.com
'
;
}
test_parse
0 → 100644
View file @
71b57491
test_shell.js
0 → 100644
View file @
71b57491
let
shell
=
require
(
'
shell-exec
'
)
tesT
()
async
function
tesT
()
{
let
d
=
await
shell
(
'
head -c 16 /dev/urandom | xxd -ps
'
)
d
=
d
.
stdout
.
replace
(
'
\n
'
,
''
)
console
.
log
(
d
)
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment