Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
T
tun
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Railgun
tun
Commits
057e78a1
Commit
057e78a1
authored
Jul 01, 2022
by
nanamicat
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
make buffer unsigned
parent
d8d45793
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
15 deletions
+12
-15
main.cpp
main.cpp
+12
-15
No files found.
main.cpp
View file @
057e78a1
#include <iostream>
#include <iostream>
#include <thread>
#include <thread>
#include <sys/socket.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/in.h>
#include <fcntl.h>
#include <fcntl.h>
...
@@ -10,37 +9,35 @@
...
@@ -10,37 +9,35 @@
#include <sys/ioctl.h>
#include <sys/ioctl.h>
#include <unistd.h>
#include <unistd.h>
#include <arpa/inet.h>
#include <arpa/inet.h>
#include <boost/program_options.hpp>
#include <boost/program_options.hpp>
namespace
po
=
boost
::
program_options
;
namespace
po
=
boost
::
program_options
;
in_addr_t
remote
;
in_addr_t
remote
;
auto
cipher
=
(
unsigned
char
*
)
"Mathematics is the art of giving the same name to different things"
;
auto
cipher
=
"Mathematics is the art of giving the same name to different things"
;
void
encrypt
(
unsigned
char
*
buffer
,
size_t
length
)
{
void
encrypt
(
char
*
buffer
,
size_t
length
)
{
for
(
auto
i
=
0
;
i
<
length
;
i
++
)
{
for
(
auto
i
=
0
;
i
<
length
;
i
++
)
{
buffer
[
i
]
^=
cipher
[
i
];
buffer
[
i
]
^=
cipher
[
i
];
}
}
}
}
void
decrypt
(
char
*
buffer
,
size_t
length
)
{
void
decrypt
(
unsigned
char
*
buffer
,
size_t
length
)
{
// xor decrypt is same as encrypt
encrypt
(
buffer
,
length
);
encrypt
(
buffer
,
length
);
}
}
// internet -> tun
// internet -> tun
void
inbound
(
int
raw
,
int
tun
)
{
void
inbound
(
int
raw
,
int
tun
)
{
char
buf
[
ETH_DATA_LEN
];
unsigned
char
buffer
[
ETH_DATA_LEN
];
sockaddr_in
address
{.
sin_family
=
AF_INET
};
sockaddr_in
address
{.
sin_family
=
AF_INET
};
socklen_t
address_length
;
socklen_t
address_length
;
size_t
packet_length
;
size_t
packet_length
;
while
((
packet_length
=
recvfrom
(
raw
,
buf
,
sizeof
(
buf
),
0
,
(
sockaddr
*
)
&
address
,
&
address_length
))
>=
0
)
{
while
((
packet_length
=
recvfrom
(
raw
,
buf
fer
,
sizeof
(
buffer
),
0
,
(
sockaddr
*
)
&
address
,
&
address_length
))
>=
0
)
{
// std::cout << "received " << packet_length << " bytes from " << inet_ntoa(address.sin_addr) << std::endl;
// std::cout << "received " << packet_length << " bytes from " << inet_ntoa(address.sin_addr) << std::endl;
auto
*
packet
=
(
iphdr
*
)
buf
;
auto
*
packet
=
(
iphdr
*
)
buf
fer
;
auto
overhead
=
packet
->
ihl
*
4
;
auto
overhead
=
packet
->
ihl
*
4
;
auto
payload
=
buf
+
overhead
;
auto
payload
=
buf
fer
+
overhead
;
auto
payload_length
=
packet_length
-
overhead
;
auto
payload_length
=
packet_length
-
overhead
;
decrypt
(
payload
,
payload_length
);
decrypt
(
payload
,
payload_length
);
if
(
write
(
tun
,
payload
,
payload_length
)
<
0
)
{
if
(
write
(
tun
,
payload
,
payload_length
)
<
0
)
{
...
@@ -52,13 +49,13 @@ void inbound(int raw, int tun) {
...
@@ -52,13 +49,13 @@ void inbound(int raw, int tun) {
// tun -> internet
// tun -> internet
void
outbound
(
int
raw
,
int
tun
)
{
void
outbound
(
int
raw
,
int
tun
)
{
char
buf
[
ETH_DATA_LEN
];
unsigned
char
buffer
[
ETH_DATA_LEN
];
sockaddr_in
address
{.
sin_family
=
AF_INET
};
sockaddr_in
address
{.
sin_family
=
AF_INET
};
address
.
sin_addr
.
s_addr
=
remote
;
address
.
sin_addr
.
s_addr
=
remote
;
size_t
packet_length
;
size_t
packet_length
;
while
((
packet_length
=
read
(
tun
,
buf
,
sizeof
(
buf
)))
>=
0
)
{
while
((
packet_length
=
read
(
tun
,
buf
fer
,
sizeof
(
buffer
)))
>=
0
)
{
encrypt
(
buf
,
packet_length
);
encrypt
(
buf
fer
,
packet_length
);
if
(
sendto
(
raw
,
buf
,
packet_length
,
0
,
(
sockaddr
*
)
&
address
,
sizeof
(
address
))
<
0
)
{
if
(
sendto
(
raw
,
buf
fer
,
packet_length
,
0
,
(
sockaddr
*
)
&
address
,
sizeof
(
address
))
<
0
)
{
perror
(
"outbound write"
);
perror
(
"outbound write"
);
}
}
}
}
...
...
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