TCP/IP 통신에서 printf() 사용시 보안상의 문제점??

clapmin의 이미지

책보다가 이런 말이 나왔습니다

"네트워크로 전달받은 문자열을 printf() 함수의 첫 번째 인자로 절대 넘겨주지 말아야 한다. 이는 심각한 보안상의 허점을 가지게 된다. printf() 대신 fputs()를 사용해야 한다." 라고 나와있는데, 저는 이부분에 대해서 전혀 이해가 안갑니다 ㅎㅎ;;
혹시 어떤 보안상의 문제점이 있을 수 있는건가요??

 의 이미지

포맷 스트링 버그(Format string bug, FSB)라고 검색해보면 나올 겁니다.
예컨대 여기(http://resources.infosecinstitute.com/format-string-bug-exploration/)라던가.

물론 공식 명칭인 것은 아니라서 언급하는 데마다 조금씩 달라지기는 해요.
영문 위키피디아에서는 Uncontrolled format string(https://en.wikipedia.org/wiki/Uncontrolled_format_string)이라는 항목에서 설명하고 있군요.
그 밖에도 끝 단어가 버그(Bug)가 아니라 취약점(Vulnerability)이나 공격(Attack)이 붙기도 합니다. 뭐 맥락에 맞게 쓰이는 거죠.
해킹 갓 배우는 뉴비들이 버퍼 오버플로우(Buffer overflow, BOF)로 첫 걸음을 뗀 다음에 맛보게 되는 분야이기도 합니다.

네트워크에서 전달받은 문자열뿐만 아니라, 그냥 일반적으로 "신뢰할 수 없는 입력"은 printf, scanf류 함수의 포맷 문자열로 넘겨 주어서는 안 됩니다.

이들 문자열은 사실 간소한 형태의 스크립트이며, printf 및 scanf류 함수들이 이 스크립트를 "실행"하는 것처럼 동작한다고 생각하면 이 취약점이 이해하기 쉬워집니다. C언어 초급자들이 막연히 알고 있는 것보다 printf, scanf류 함수들은 상당히 많은 기능을 갖고 있거든요. 물론 perl이나 python처럼 편리하고 강력하지는 않지만, 이것만으로도 어떻게 공격이 이루어지는지는 검색해 보면 여러 사례가 나올 거에요.

옛날에 누가 printf("%x %x %x %x %x %x");만으로 서버를 뚫었다는 무용담을 어디서 들은 적이 있는데, 뭘 어떻게 했다는 건지는 못 들었고 사실 지금도 이해가 안 됩니다. 스택의 24바이트를 덤프 뜨게 되는데, 거기에 무슨 귀중한 정보라도 묻어나오게 할 수 있나 보죠?

덧. 사용할 수 있는 HTML 태그에 분명히 <a>이 있는데, 왜 직접 이 태그를 쓰려고 하면 게시가 안 되는 거죠? 링크 없이 url을 그냥 쓰니까 지저분해지는군요. -_-;;

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.