Professional Documents
Culture Documents
Buffer Overflow Attacks
Buffer Overflow Attacks
Secure coding
COMMON C
FUNCTIONS USED
TO CARRY OUT
BUFFER
OVERFLOW
ATTACKS
RPB - TEAM
Buffer overflow attacks in IoT devices are often carried out by common C library functions that are
designed to copy or manipulate data in memory buffers. These include:
VULNERABLE C
DESCRIPTION EN DESCRIPTION AR
FUNCTION
This function copies data from one memory location ال يقوم.تقوم هذه الوظيفة بنسخ البيانات من موقع ذاكرة إلى آخر
to another. It does not perform any size checking, so لذلك يمكن استخدامه لنسخ المزيد من البيانات، بأي فحص للحجم
memcpy it can be used to copy more data into a buffer than ، في المخزن المؤقت أكثر من المخزن المؤقت المصمم لالحتفاظ به
the buffer is designed to hold, potentially leading to a
.مما قد يؤدي إلى ثغرة أمنية في تجاوز سعة المخزن المؤقت
buffer overflow vulnerability.
This function copies a string from one buffer to مثل.تقوم هذه الوظيفة بنسخ سلسلة من مخزن مؤقت إلى آخر
another. Like memcpy, it does not perform any size
لذلك يمكن استخدامه لنسخ، ال يقوم بأي فحص للحجم، memcpy
strcpy checking, so it can be used to copy a string larger
مما، سلسلة أكبر من المخزن المؤقت الوجهة في المخزن المؤقت
than the destination buffer into the buffer, potentially
leading to a buffer overflow vulnerability. .قد يؤدي إلى ضعف سعة المخزن المؤقت
This function formats and stores a string in a تعمل هذه الوظيفة على تنسيق سلسلة وتخزينها في مخزن
buffer. Like strcpy, it does not perform any size لذلك يمكن، ال يقوم بأي فحص للحجم، strcpy مثل.مؤقت
sprintf checking, so it can be used to write a string استخدامه لكتابة سلسلة أكبر من المخزن المؤقت في المخزن
larger than the buffer into the buffer, potentially . مما قد يؤدي إلى ضعف سعة المخزن المؤقت، المؤقت
leading to a buffer overflow vulnerability.
RPB -TEAM
Buffer Copy without Checking Size of Input
RPB - TEAM
#include <stdio.h>
#include <string.h>
printf("%s\n", buffer2);
return 0;
}
@ RA'AD M. ABU JAISH
RPB - TEAM
#include <stdio.h>
#include <string.h>
printf("%s\n", buffer2);
return 0;
}
VULNERABLE C
DESCRIPTION EN DESCRIPTION AR
FUNCTION
This function is a safe alternative to gets(). It وتخزينها في مخزنstdin تقوم هذه الوظيفة بقراءة األحرف من
ال يتحقق من حجم.مؤقت حتى يتم العثور على حرف سطر جديد
gets reads a line from the input stream and stores it
in a buffer, taking care not to exceed the المخزن المؤقت ويمكن أن يؤدي إلى ثغرات تجاوز سعة المخزن
buffer's size. .المؤقت
This function reads input from stdin and tries to parse وتحاول تحليلها وفًق اstdin تقرأ هذه الوظيفة المدخالت من
it according to a format string. Like gets, it does not
فإنه ال يتحقق من حجم المخزن، get مثل.لسلسلة التنسيق
scanf check the size of the input buffer and can cause
buffer overflow vulnerabilities.
المؤقت لإلدخال ويمكن أن يسبب ثغرات في تجاوز سعة المخزن
.المؤقت
This function reads input from stdin and tries to parse يقرأ سطًر ا من دفق.)( هذه الوظيفة هي بديل آمن للحصول على
it according to a format string. Like gets, it does not
مع الحرص على عدم تجاوز حجم، اإلدخال ويخزنه في مخزن مؤقت
fgets check the size of the input buffer and can cause
buffer overflow vulnerabilities.
.المخزن المؤقت
char str[21];
.األحرف للقراءة
scanf("%20s", str);
scanf(“%9s”, &name);
scanf(“%s”, &name);
RPB - TEAM
#include <stdio.h>
#include <string.h>
int main() {
char name[10];
int age;
return 0;
}
vfprintf Prints the a va_arg structure to a file إلى ملفva_arg يطبع بنية
Below are some format parameters which can be used and their consequences:
External representation of a
%p pointer to void
Reference
%d Decimal Value
%c Character
%x Hexadecimal Value
%s String Reference
#include <stdio.h>
void main(int argc, char **argv)
{char buf[100];
snprintf(buf, sizeof buf, argv[1]);}
RPB - TEAM
#include <stdio.h>
void main(int argc, char **argv)
{char buf[100];
snprintf(buf, sizeof buf,"%s", argv[1]);}