Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code signing support #130

Open
wants to merge 43 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
2aa8af6
with -s there
banister Dec 7, 2017
dacf97a
Got it to output the NT signature ('PE')
banister Dec 7, 2017
209f994
Found the place where the signature starts (just after the end of the…
banister Dec 7, 2017
c23b023
Got isDigitallySigned and retrieveNTHeader working
banister Dec 8, 2017
3ff1a0b
Skip over null bytes between ocrasig and digital sig
banister Dec 8, 2017
8079207
Minor refactor to stub.c
banister Dec 8, 2017
be03031
remove whitespace
banister Dec 8, 2017
2ebf89b
remove unnecessary brackets
banister Dec 8, 2017
3479495
add better var names and add a macro
banister Dec 8, 2017
f47c6fc
minor sylistic changes
banister Dec 8, 2017
08eb35b
language change
banister Dec 8, 2017
cffb014
Make functions static
banister Dec 8, 2017
a9e4cae
reorg rakefile
banister Dec 8, 2017
8677190
update comments based on PR feedback from @jakedouglas
banister Dec 12, 2017
227c3f0
rewrite comment based on feedback from @jakedouglas
banister Dec 12, 2017
20aa6b5
Add code signing doc for easy review, won't necessarily keep in this …
banister Dec 12, 2017
d435c3e
tweaks to doc
banister Dec 12, 2017
11c7aa8
Add higher res image
banister Dec 12, 2017
6fcf63a
RVA means relative virtual address not relative virtual offset
banister Dec 12, 2017
1c60817
minor tweaks to language
banister Dec 12, 2017
a8f8ba5
language change
banister Dec 12, 2017
0368c88
language tweak
banister Dec 12, 2017
a201ed7
include dos header in diagram
banister Dec 12, 2017
5fbc596
Simplify language
banister Dec 12, 2017
7b9996e
signed -> encrypted
banister Dec 12, 2017
288b98a
fix typo
banister Dec 13, 2017
0f04ea5
remove repetition
banister Dec 13, 2017
6063b11
Commit FakeCodeSigner
banister Dec 14, 2017
261d751
Add specs for code signing
banister Dec 14, 2017
7407583
Extract out PEHeader and write more docs
banister Dec 14, 2017
988ee44
DATA_DIRECTORY_ENTRY_SIZE is 8 (2 DWORDs) not 4
banister Dec 14, 2017
cf62394
Remove changes friendly to local development
banister Dec 14, 2017
05568b0
Remove more unnecessary files
banister Dec 14, 2017
4005673
Revert to original spacing (3 not 2)
banister Dec 14, 2017
d9f208b
Add more comments to fake_code_signer.rb
banister Dec 14, 2017
32b7d2e
use DWORD_SIZE in more places
banister Dec 14, 2017
43590f5
add explicit offset methods
banister Dec 14, 2017
5997c12
Rename pe_header -> pe_wrapper
banister Dec 14, 2017
a013074
Introduce PEWrapper#to_s
banister Dec 14, 2017
fe53059
Make comments more explicit
banister Dec 14, 2017
250b76c
input -> input_file, h/t @jakedouglas
banister Dec 14, 2017
460eb52
update specs with new names
banister Dec 14, 2017
335acf7
use input_file not input
banister Dec 14, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Got it to output the NT signature ('PE')
banister committed Dec 7, 2017
commit dacf97ad95213fa8fd9badf6dc8a31f591f499ac
11 changes: 11 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -12,6 +12,17 @@ end

spec.urls.each { |url| url.chomp! }

desc "task for fast iteration"
task :do_it do
sh "rake install_gem" rescue nil
sh "gem uninstall ocra"
puts "installing the bitch"
sh "gem install pkg/ocra-1.4.666.gem"
sh "rm hello.exe" rescue nil
sh "ocra hello.rb"
sh "./hello.exe"
end

task :build_stub do
sh "mingw32-make -C src"
cp 'src/stub.exe', 'share/ocra/stub.exe'
6 changes: 3 additions & 3 deletions src/Makefile
Original file line number Diff line number Diff line change
@@ -3,8 +3,8 @@ OBJS = $(SRCS:.c=.o) stubicon.o
CC = gcc
BINDIR = $(CURDIR)/../share/ocra

CFLAGS = -Wall -O0 -ggdb
STUB_CFLAGS = -D_CONSOLE $(CFLAGS) -s
CFLAGS = -Wall -O2 -DWITH_LZMA -Ilzma -s
STUB_CFLAGS = -D_CONSOLE $(CFLAGS)
STUBW_CFLAGS = -mwindows $(CFLAGS)
# -D_MBCS

@@ -14,7 +14,7 @@ stubicon.o: stub.rc
windres -i $< -o $@

stub.exe: $(OBJS) stub.o
$(CC) $(STUB_CFLAGS) stub.o -o stub
$(CC) $(STUB_CFLAGS) $(OBJS) stub.o -o stub

stubw.exe: $(OBJS) stubw.o
$(CC) $(STUBW_CFLAGS) $(OBJS) stubw.o -o stubw
9 changes: 9 additions & 0 deletions src/stub.c
Original file line number Diff line number Diff line change
@@ -366,13 +366,22 @@ int CALLBACK _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCm
return 0;
}

void ExamineSignature(LPVOID ptr) {
PIMAGE_DOS_HEADER dosHeader = (PIMAGE_DOS_HEADER)ptr;
PIMAGE_NT_HEADERS ntHeader = (PIMAGE_NT_HEADERS)((DWORD)dosHeader + (DWORD)dosHeader->e_lfanew);
printf("e_lfanew: %lu\n", dosHeader->e_lfanew);
printf("NT signature: %s\n", (char*)&ntHeader->Signature);
}

/**
Process the image by checking the signature and locating the first
opcode.
*/
BOOL ProcessImage(LPVOID ptr, DWORD size)
{
LPVOID pSig = ptr + size - 4;
ExamineSignature(ptr);

if (memcmp(pSig, Signature, 4) == 0)
{
DEBUG("Good signature found.");