Secure coding: Difference between revisions

Content deleted Content added
m Reverted edits by Nehirdemir (talk): disruptive edits (HG) (3.3.5)
Line 8:
'''Secure coding''' is the practice of developing computer [[software]] in a way that guards against the accidental introduction of security vulnerabilities. Defects, bugs and logic flaws are consistently the primary cause of commonly exploited software vulnerabilities.<ref name="bss2001">{{Cite book| last = Viega | first = John |author2=Gary McGraw | title = Building Secure Software: How to Avoid Security Problems the Right Way | year = 2001 | publisher = MAddison-Wesley Professional | pages = 528 | isbn = 978-0201721522 | page = }}</ref> Through the analysis of thousands of reported vulnerabilities, security professionals have discovered that most vulnerabilities stem from a relatively small number of common software programming errors. By identifying the insecure coding practices that lead to these errors and educating developers on secure alternatives, organizations can take proactive steps to help significantly reduce or eliminate vulnerabilities in software before deployment.
 
== Ara BellekBuffer-taşmasıoverflow önlemiprevention ==
[[Buffer overflow]]s, a common software security vulnerability, happen when a process tries to store data beyond a fixed-length buffer. For example, if there are 8 slots to store items in, there will be a problem if there is an attempt to store 9 items. In computer memory the overflowed data may overwrite data in the next ___location which can result in a security vulnerability (stack smashing) or program termination (segmentation fault).<ref name="bss2001"/>
[[Ara Bellek Taşması]],İşlemci belirlenen ara bellek uzunluğunu aştığında ortaya çıkan genel yazılım güvenlik açığıdır. Örneğin veri ögelerini saklamak için 8 bölüt varsa,9 veri ögesi saklanmak istenildiğinde problem ortaya çıkar.Bilgisayar belleği taşan veri sorunuyla karşılaştığında verinin bir sonraki yerine üstüne yazma işlemi gerçekleştirir,bu da güvenlik zafiyetine(yığın aşılması) veya programın bitirilmesine(bölümlendirme hatası) sebebiyet verebilir.<ref name="bss2001"/>
 
araAn bellekexample taşmasınaof eğilimi olan bir Ca [[C (programlamaprogramming dililanguage)|C]] programıprogram prone to a aşağıdabuffer verilmiştir.overflow is<syntaxhighlight lang="c++">
int vulnerable_function(char * large_user_input) {
char dst[SMALL];
strcpy(dst, large_user_input);
}
</syntaxhighlight>EğerIf kullanıcıthe hedefuser bellekteninput dahais büyüklarger birthan girdithe verirsedestination buffer,ara belleka buffer taşmasıoverflow meydanawill gelebiliroccur.
 
BuTo tehlikelifix programıthis düzeltmekunsafe içinprogram, strncpyuse metodustrncpy olasıto araprevent belleka taşmasıpossible probleminibuffer önleyebiliroverflow.<syntaxhighlight lang="c++">
int secure_function(char * user_input) {
char dst[BUF_SIZE];
Line 24:
strncpy(dst, user_input,BUF_SIZE);
}
</syntaxhighlight>DiğerAnother güvenlisecure seçenekalternative iseis hafızayıto dinamikdynamically olarakallocate yığınmemory yapısıylaon the heap using ayırmaktır.[[malloc]].<syntaxhighlight lang="c++">
char * secure_copy(char * src) {
int len = strlen(src);
Line 35:
return dst;
}
</syntaxhighlight>YukarıdakiIn kodthe parçasındaabove code snippet, the program attempts to copy the contents of '''''src''''' into '''''dst,''''' içerikleriniwhile kopyalar,bunualso yaparkenchecking dethe return value of malloc'tan gelento ensure that enough dönüşmemory tipiniwas kontrolable ederto kibe hedefallocated belleğinfor yeterlithe hafızasıdestination olsunbuffer.
 
== BiçimFormat-Dizgistring Saldırısıattack Önlemleriprevention ==
A [[Format string attacks|Format String Attack]] is when a malicious user supplies specific inputs that will eventually be entered as an argument to a function that performs formatting, such as [[printf()]]. The attack involves the adversary reading from or writing to the [[Call stack|stack]].
[[Biçim Dizgi Saldırısı|Format String Attack]] kötü amaçlı kullanıcının fonksiyon içine argüman olarak spesifik girdiler vererek biçimlendirmeye çalışmasıdır,örneğin [[printf()]] bir biçim-dizgi saldırısıdır.Düşman kişi okuma ve yazma yaparak saldırıyı gerçekleştirebilir. [[Çağrı yığıtı|stack]].
 
The C printf function writes output to stdout. If the parameter of the printf function is not properly formatted, several security bugs can be introduced. Below is a program that is vulnerable to a format string attack.<syntaxhighlight lang="c++">
C fonksiyonu çıktıyı stdout a yazar.Eğer parametreler biçimsel olarak uygun değilse,çeşitli güvenlik hatalarıyla karşılaşılabilir.Aşağıda biçim dizgi hatasına sebebiyet verebilecek örnek bir program verilmiştir.<syntaxhighlight lang="c++">
int vulnerable_print(char * malicious_input) {
printf(malicious_input);
}
</syntaxhighlight>ProgramınA uygunsuzmalicious hafızaargument okumasındanpassed dolayıto sonathe erdirebilecekprogram hatalıcould olarak verilebilecek argümanbe “%s%s%s%s%s%s%s”, parametrewhich can crash the program from improper olarakmemory verilmiştirreads.
 
== Integer-overflow prevention ==