Skip to content

Reverse shell for GnuCOBOL, written in the IBM COBOL standard.

License

Notifications You must be signed in to change notification settings

wglobke/COBOL-reverse-shell

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 

Repository files navigation

COBOL-reverse-shell

Reverse shell for GnuCOBOL, written in the IBM COBOL standard. This is essentially a COBOL wrapper for the C system library, to which the GnuCOBOL runtime allows easy access.

Compile on the command line with

cobc -x -std=ibm reverseshell.cob

The flag -x will create an executable "reverseshell", and the flag -std=IBM makes sure we use IBM COBOL as the language (the different COBOL dialects are obscenely incompatible with one another, so it is likely this code will not run with any other).

The sockaddr structure for the connect call is built according to the BSD/macOS convention, with fields sin_len, sin_family, sin_port and sin_addr. Since one cannot define single byte values in IBM COBOL, I combine sin_len and sin_family into a two-byte entry called sin_len_sin_family. It must have the value 0x0002. The IP address and port of the listener are hard-coded as decimal values in the variables

sin_port as 1234,

sin_addr as 167772173.

Replace these by your own values. Note that you do not have to reverse the byte order to Big Endian (as is required by the socket call), because this is done automatically when GnuCOBOL compiles the program. This also mean we can assign

sin_len_sin_family as 2

since this will be byte-swapped by IBM COBOL and thus be put in the correct order for the sockaddr structure. If you want to run this on Linux, there is no sin_len field, but sin_family is two bytes long instead, so the overall size does not differ. To get the order right after the byte-swap, you would have to assign the value 0x0200, or decimal 512, to the variable sin_len_sin_family on Linux.

It is interesting to see the corresponding C-code. This can be obtained by

cobc -C -std=IBM reverseshell.cob

which creates three files,

reverseshell.c.h global variables

reverseshell.c.l.h local variables

reverseshell.c program as a library

These files are particularly helpful when debugging function calls to the C-library.

Of course this is a silly idea. :)

About

Reverse shell for GnuCOBOL, written in the IBM COBOL standard.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages