countdown to B-Sides Detroit!
Security B-Sides Detroit is coming up soon, and it's going to be awesome. i will be giving a talk there on June 2 at 2:00pm about research i have done into HTTP Strict Transport Security. aside from that, there are two full days of talks and workshops; whatever your niche of interest within information security, there will be talks there to engage you and make you think. if there is any way you can get to Detroit that weekend, please make your plans, and get a ticket to B-Sides Detroit!
in anticipation of B-Sides Detroit, mwjcomputing and Tazdrumm3r have written scripts in several languages to print countdowns to B-Sides Detroit. mwjcomputing shared scripts in PowerShell, bash, and Ruby on his blog; Tazdrumm3r did his in Python.
i thought this was a fun idea, and i wanted to write a script. Python and bash are the languages i program in most often nowadays, but obviously i couldn't just redo the script in a language that had already been done. i love to program in x86 assembly, but hadn't had an excuse to use it much lately, so i decided to see if i could write my countdown script in it. after intermittently bashing my head against it for the last two days, racking up more segfaults than i could count, and becoming very good friends with gdb, i managed to get some code that works.
this should assemble and link, with nasm and ld respectively, on a 32-bit Linux machine. you can download the source code (which is far more readable, because it has things like "indentations" and "linebreaks" that the code tag seems to hate) or my executable (compiled in 32-bit openSUSE) here.
if you don't feel like downloading anything, here's what i hacked up:
; untilbsides.asm
; counts down days, minutes, and seconds until BSidesDetroit 2012
; by rogueclown
; May 16-17, 2012
; licensed under WTFPL
global _start
section .data
nextyear db "Wait 'til next year for BSidesDetroit!", 0x0a
nextlen equ $ - nextyear
itsnow db "BSidesDetroit 2012 is now! Be there!", 0x0a
nowlen equ $ - itsnow
thereare db "There are "
therelen equ $ - thereare
untilare db " seconds until BSidesDetroit 2012! Make your plans!", 0x0a
untillen equ $ - untilare
daytohour db " days, "
dthlen equ $ - daytohour
hourtomin db " hours, "
htmlen equ $ - hourtomin
mintosec db " minutes, and "
mtslen equ $ - mintosec
section .bss
counter resb 4 ; generic counter for packing digits
digit resb 4 ; holder for digit
days: resb 4 ; days until BSidesDetroit
daystringlen: resb 4 ; length of days string
hours: resb 4 ; hours in fractional days
hourstringlen: resb 4 ; length of hours string
minutes: resb 4 ; minutes in fractional hour
minstringlen: resb 4 ; length of minutes string
seconds: resb 4 ; seconds in fractional minute
secstringlen: resb 4 ; length of seconds string
section .text
_start:
; get the current system time
mov eax, 13
int 0x80
; unix 1338559200 is 9am on June 1, 2012
; unix 1338681600 is 7pm on June 2, 2012
; test if BSidesDet 2012 has passed
cmp eax, 1338681600
jg toolate
; if it hasn't passed, test if BSidesDet is going on
cmp eax, 1338559200
jge now
; otherwise, calculate days until BSidesDet
jmp daysuntil
toolate:
; tell user to wait until next year
mov eax, 4
mov ebx, 1
mov ecx, nextyear
mov edx, nextlen
int 0x80
; exit gracefully
jmp exit
now:
; tell user to get there now, it's starting!
mov eax, 4
mov ebx, 1
mov ecx, itsnow
mov edx, nowlen
int 0x80
;exit gracefully
jmp exit
daysuntil:
; get the number of seconds until BSidesDetroit starts
; the current unix time is still in eax
mov ebx, eax
mov eax, 1338559200
sub eax, ebx
; eax contains the number of seconds until BSidesDetroit
; there are 86400 seconds in a day
mov edx, 0
mov ecx, 86400
div ecx
; save number of days
mov [days], eax
; move remainder seconds (partial day) to eax
mov eax, edx
; there are 3600 seconds in an hour
mov edx, 0
mov ecx, 3600
div ecx
; save number of hours
mov [hours], eax
; move remainder seconds (partial hours) to eax
mov eax, edx
; there are 60 seconds in a minute
mov edx, 0
mov ecx, 60
div ecx
; save number of hours, and leftover seconds
mov [minutes], eax
mov [seconds], edx
; initialize counter variables for numbers
mov eax, 0
mov [counter], eax
mov [daystringlen], eax
mov [hourstringlen], eax
mov [minstringlen], eax
mov [secstringlen], eax
; prepare strings to display time left until BSidesDet 2012
stringsecs:
mov eax, [seconds]
digitsecs:
mov edx, 0
mov ecx, 10
div ecx
add edx, 0x30
; push digit in edx onto stack
push edx
; count digit
inc word [secstringlen]
; if all digits have been created, move to minutes
cmp eax, 0
jne digitsecs
stringmins:
mov eax, [minutes]
digitmins:
mov edx, 0
mov ecx, 10
div ecx
add edx, 0x30
; push digit in edx onto stack
push edx
; count digit
inc word [minstringlen]
; if all digits have been created, move to hours
cmp eax, 0
jne digitmins
stringhours:
mov eax, [hours]
digithours:
mov edx, 0
mov ecx, 10
div ecx
add edx, 0x30
; push digit in edx onto stack
push edx
; count digit
inc word [hourstringlen]
; if all digits have been created, move to days
cmp eax, 0
jne digithours
stringdays:
mov eax, [days]
digitdays:
mov edx, 0
mov ecx, 10
div ecx
add edx, 0x30
; push digit in edx onto stack
push edx
; count digit
inc word [daystringlen]
cmp eax, 0
jne digitdays
printcountdown:
; print out the intro string
mov eax, 4
mov ebx, 1
mov ecx, thereare
mov edx, therelen
int 0x80
printdays:
; print days digits from stack
pop eax
mov [digit], eax
mov eax, 4
mov ebx, 1
mov ecx, digit
mov edx, 1
int 0x80
inc word [counter]
mov eax, [counter]
mov ebx, [daystringlen]
cmp eax, ebx
jl printdays
; segue from days to hours
mov eax, 4
mov ebx, 1
mov ecx, daytohour
mov edx, dthlen
int 0x80
; reset counter before printing hours
mov eax, 0
mov [counter], eax
printhours:
; print hours digits from stack
pop eax
mov [digit], eax
mov eax, 4
mov ebx, 1
mov ecx, digit
mov edx, 1
int 0x80
inc word [counter]
mov eax, [counter]
mov ebx, [hourstringlen]
cmp eax, ebx
jl printhours
; segue from hours to minutes
mov eax, 4
mov ebx, 1
mov ecx, hourtomin
mov edx, htmlen
int 0x80
; reset counter before printing minutes
mov eax, 0
mov [counter], eax
printmins:
; print minutes digits from stack
pop eax
mov [digit], eax
mov eax, 4
mov ebx, 1
mov ecx, digit
mov edx, 1
int 0x80
inc word [counter]
mov eax, [counter]
mov ebx, [minstringlen]
cmp eax, ebx
jl printmins
; segue to seconds
mov eax, 4
mov ebx, 1
mov ecx, mintosec
mov edx, mtslen
int 0x80
; reset counter before printing seconds
mov eax, 0
mov [counter], eax
printsecs:
; print seconds digits from stack
pop eax
mov [digit], eax
mov eax, 4
mov ebx, 1
mov ecx, digit
mov edx, 1
int 0x80
inc word [counter]
mov eax, [counter]
mov ebx, [secstringlen]
cmp eax, ebx
jl printsecs
; finish message
mov eax, 4
mov ebx, 1
mov ecx, untilare
mov edx, untillen
int 0x80
exit:
mov eax, 1
mov ebx, 0
int 0x80
enjoy!



