Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
B
bytevia
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Michael Pastushkov
bytevia
Commits
f6e30b9e
Commit
f6e30b9e
authored
Sep 16, 2024
by
michaelpastushkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cipher update freq
parent
a8080874
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
40 additions
and
36 deletions
+40
-36
src/bytevia.c
+33
-30
src/bytevia.h
+7
-6
No files found.
src/bytevia.c
View file @
f6e30b9e
...
...
@@ -63,7 +63,7 @@ static struct option long_options[] = {
const
char
*
name
=
NAME
;
unsigned
char
cipher
[
256
];
int
cipher_
day
;
int
cipher_
time
;
char
*
get_current_timestamp
(
void
)
{
static
char
date_str
[
20
];
...
...
@@ -103,29 +103,29 @@ unsigned int get_hash(unsigned int source) {
return
hash
;
}
int
get_
utc_day_of_month
()
{
time_t
now
=
time
(
NULL
);
struct
tm
*
utc_time
=
gmtime
(
&
now
);
return
utc_time
->
tm_mday
;
int
get_
time
()
{
time_t
now
=
time
(
NULL
);
return
now
/
(
60
*
10
);
/* changing cipher every 10 minutes */
}
void
update_cipher
()
{
int
i
;
unsigned
int
seed
;
int
day
=
get_utc_day_of_month
();
if
(
day
==
cipher_day
)
int
time
=
get_time
();
if
(
time
==
cipher_time
)
return
;
for
(
i
=
0
;
i
<
256
;
i
++
)
cipher
[
i
]
=
i
;
seed
=
get_hash
(
options
.
secret
*
day
);
seed
=
get_hash
(
options
.
secret
*
time
);
shuffle
(
cipher
,
sizeof
(
cipher
),
seed
);
if
(
options
.
log
)
{
printf
(
"%s new cipher %i
\n
"
,
get_current_timestamp
(),
day
);
if
(
options
.
log
>
1
)
{
printf
(
"%s new cipher %i
\n
"
,
get_current_timestamp
(),
time
);
if
(
options
.
log
>
2
)
{
for
(
i
=
0
;
i
<
256
;
i
++
)
{
printf
(
"%d "
,
cipher
[
i
]);
...
...
@@ -134,7 +134,7 @@ void update_cipher() {
}
}
}
cipher_
day
=
day
;
cipher_
time
=
time
;
}
int
encode
(
unsigned
char
*
buf
,
int
len
)
{
...
...
@@ -236,7 +236,7 @@ int build_tcp(void) {
return
0
;
}
int
wait_
for_clients
(
void
)
{
int
wait_
connection
(
void
)
{
#if defined(__MINGW32__) || defined(__CYGWIN__)
int
client_addr_size
;
...
...
@@ -268,11 +268,11 @@ int wait_for_clients(void) {
return
0
;
}
int
build
_tunnel
(
void
)
{
int
build
(
void
)
{
rc
.
remote_host
=
gethostbyname
(
options
.
remote_host
);
if
(
rc
.
remote_host
==
NULL
)
{
perror
(
"build
_tunnel
: gethostbyname()"
);
perror
(
"build: gethostbyname()"
);
return
1
;
}
...
...
@@ -283,20 +283,20 @@ int build_tunnel(void) {
rc
.
remote_socket
=
socket
(
AF_INET
,
options
.
proto
,
0
);
if
(
rc
.
remote_socket
<
0
)
{
perror
(
"build
_tunnel
: socket()"
);
perror
(
"build: socket()"
);
return
1
;
}
if
(
options
.
proto
==
SOCK_STREAM
)
{
if
(
connect
(
rc
.
remote_socket
,
(
struct
sockaddr
*
)
&
rc
.
remote_addr
,
sizeof
(
rc
.
remote_addr
))
<
0
)
{
perror
(
"build
_tunnel
: connect()"
);
perror
(
"build: connect()"
);
return
1
;
}
}
return
0
;
}
int
use
_tunnel
(
void
)
int
use
(
void
)
{
fd_set
io
;
unsigned
char
buffer
[
options
.
buffer_size
];
...
...
@@ -314,7 +314,7 @@ int use_tunnel(void)
/* Waiting for data */
if
(
select
(
max_fd
+
1
,
&
io
,
NULL
,
NULL
,
NULL
)
<
0
)
{
perror
(
"use
_tunnel
: select()"
);
perror
(
"use: select()"
);
break
;
}
...
...
@@ -326,7 +326,7 @@ int use_tunnel(void)
recv
(
rc
.
client_socket
,
buffer
,
sizeof
(
buffer
),
0
);
if
(
count_recv
<
0
)
{
perror
(
"use
_tunnel
: recv(rc.client_socket)"
);
perror
(
"use: recv(rc.client_socket)"
);
close
(
rc
.
client_socket
);
close
(
rc
.
remote_socket
);
return
1
;
...
...
@@ -358,7 +358,7 @@ int use_tunnel(void)
recv
(
rc
.
remote_socket
,
buffer
,
sizeof
(
buffer
),
0
);
if
(
count_recv
<
0
)
{
perror
(
"use
_tunnel
: recv(rc.remote_socket)"
);
perror
(
"use: recv(rc.remote_socket)"
);
close
(
rc
.
client_socket
);
close
(
rc
.
remote_socket
);
return
1
;
...
...
@@ -384,25 +384,25 @@ int use_tunnel(void)
return
0
;
}
void
handle_tunnel
(
void
)
{
if
(
build
_tunnel
()
==
0
)
use
_tunnel
();
void
run
(
void
)
{
if
(
build
()
==
0
)
use
();
}
void
handle_client
(
void
)
{
void
serve
(
void
)
{
#ifdef __MINGW32__
handle_tunnel
();
run
();
#else
if
(
options
.
fork
)
{
if
(
fork
()
==
0
)
{
close
(
rc
.
server_socket
);
handle_tunnel
();
run
();
exit
(
0
);
}
close
(
rc
.
client_socket
);
}
else
{
handle_tunnel
();
run
();
}
#endif
}
...
...
@@ -457,7 +457,10 @@ void init_options() {
memset
(
&
options
,
0
,
sizeof
(
options
));
/* defaults */
options
.
buffer_size
=
MINIMUM_BUFFER_SIZE
;
options
.
local_port
=
LOCAL_PORT
;
options
.
remote_host
=
REMOTE_HOST
;
options
.
remote_port
=
REMOTE_PORT
;
options
.
buffer_size
=
BUFFER_SIZE
;
options
.
bind_address
=
"0.0.0.0"
;
options
.
proto
=
SOCK_STREAM
;
options
.
log
=
1
;
...
...
@@ -638,9 +641,9 @@ int main(int argc, char *argv[]) {
do
{
if
(
wait_
for_clients
()
==
0
)
if
(
wait_
connection
()
==
0
)
{
handle_client
();
serve
();
}
}
while
(
options
.
stay_alive
);
...
...
src/bytevia.h
View file @
f6e30b9e
...
...
@@ -3,6 +3,13 @@
#define NAME "bytevia"
#define VERSION "1.0"
#define REMOTE_HOST "p4pn.net"
#define REMOTE_PORT 1948
#define LOCAL_PORT 1984
#define BUFFER_SIZE 4096
#define MODE_CLIENT 0
#define MODE_SERVER 1
#define LOCAL_PORT_OPTION 'a'
#define REMOTE_HOST_OPTION 'b'
...
...
@@ -20,12 +27,6 @@
#define SECRET_OPTION 'n'
#define PROTO_OPTION 'o'
#define MODE_CLIENT 0
#define MODE_SERVER 1
#define MINIMUM_BUFFER_SIZE 4096
#define PATH_SEPARATOR '/'
struct
struct_options
{
unsigned
int
local_port
;
char
*
remote_host
;
...
...
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