# The Linux Virus Writing HOWTO

#### post-link-time code modification of ELF executables under Linux/i386

Abstract
This document describes how to write parasitic file viruses infecting ELF executables on Linux/i386. Though it contains a lot of source code, no actual virus is included. Unfinished excerpt sent to Linux Documentation Project on 2002-03-11.

# Introduction

Writing a program that inserts code into another program file is one thing. Writing that program so that it can be inserted itself is a very different art. So although this document shows a lot of code and technique, it is far from being a "Construction Kit For Dummies". Instead I'll try to show how things work. Translation of infecting code to assembly is left as a (non-trivial) exercise to the reader.

An astonishing number of people think that viruses require secret black magic. Here you will find simple code that patches other executables. But since regular users can't overwrite system files (we are talking about serious operating systems here) that is not even half the journey. To make any impact you need root permissions. Either by tricking the super user to run your virus, or combining it with a root-exploit. And since all popular distributions come with checksum mechanisms, a single command can detect any modification. Unless you implement kernel-level stealth functionality…

I do believe that free software is superior, at least in regard to security. And I strongly oppose the argument that Linux viruses will flourish once it reaches a critical mass of popularity. On the contrary I question the credibility of people whose income relies on widespread use of ridiculously insecure operating systems.

This document is my way to fight the FUD. Use the information presented here in any way you like. I bet that Linux will only grow stronger.

## Behind the stages

All sections titled "Output" are real product of source code and shell scripts included in this document. Most numbers and calculations are processed by a perl-script parsing these output files. The document itself is written in DocBook, a SGML document type definition. Conversion to HTML is the last step of a Makefile that builds and runs all examples.

I used an installation of RedHat 7.2 for development All required tools are contained on the two freely downloadable CDs .

## Copyright Information

This document is copyrighted (c) 2002 Alexander Bartolich and is distributed under the terms of the Linux Documentation Project (LDP) license, stated below.

Unless otherwise stated, Linux HOWTO documents are copyrighted by their respective authors. Linux HOWTO documents may be reproduced and distributed in whole or in part, in any medium physical or electronic, as long as this copyright notice is retained on all copies. Commercial redistribution is allowed and encouraged; however, the author would like to be notified of any such distributions.

All translations, derivative works, or aggregate works incorporating any Linux HOWTO documents must be covered under this copyright notice. That is, you may not produce a derivative work from a HOWTO and impose additional restrictions on its distribution. Exceptions to these rules may be granted under certain conditions; please contact the Linux HOWTO coordinator at the address given below.

In short, we wish to promote dissemination of this information through as many channels as possible. However, we do wish to retain copyright on the HOWTO documents, and would like to be notified of any plans to redistribute the HOWTOs.

If you have any questions, please contact `<linux-howto@metalab.unc.edu>`

## Disclaimer

No liability for the contents of this documents can be accepted. Use the concepts, examples and other content at your own risk. As this is a new edition of this document, there may be errors and inaccuracies, that may of course be damaging to your system. Proceed with caution, the author does not take any responsibility.

All copyrights are held by their by their respective owners, unless specifically noted otherwise. Use of a term in this document should not be regarded as affecting the validity of any trademark or service mark.

Naming of particular products or brands should not be seen as endorsements.

You are strongly recommended to take a backup of your system before major installation and backups at regular intervals.

## New Versions

2002-03-09. Unfinished excerpt sent to Linux Documentation Project.

2002-03-11. Unfinished excerpt sent to Linux Documentation Project. Section One step closer to the edge rewritten & finished.

## Feedback

Feedback is most certainly welcome for this document. Please send your additions, comments and criticisms to the following email address: `<alexander.bartolich@gmx.at>`

|  | Next >>>
|  | The magic of the Elf