iT邦幫忙

2021 iThome 鐵人賽

DAY 28
0
Security

過關斬將,資安面試300題系列 第 28

程式語言篇

學資安需要會寫程式嗎?

最近才看到PTT有人問了類似的問題,
大致上的內容就是詢問說想走資安,但不會寫程式可以嗎之類。
資安需不需要會寫程式,相信應該是許多人的疑惑,
這個問題沒有辦法三言兩語簡單的回答,
不僅僅題目過於模糊,牽扯的事情也太過廣泛,
資安有許多的領域(光是我這系列主題就可以看出了吧XD),
每個領域都會有不同的需求,
而不同的公司、單位、職位都會有所差異。

就算說不會程式也可以走資安,
那如果我跟你說了,在資安領域裡面會寫程式的,多數發展比較好,
你覺得這樣算不算是可以不用會寫程式?

所謂的會寫程式又是甚麼呢?
我學過JS、Java、PHP、Python、C、Shell Script等等
但有好幾個都只會很簡單的用法,要寫好一個程式也是要邊Google邊寫,
這樣對你來說算是會寫嗎?

這個問題答案可以簡單也可以複雜,
但我覺得很難得到一個負責任的好答案。

所以我先來個不負責任的微答案XD
偏稽核管理層面的,通常不太需要寫程式;
偏技術相關職務的,有的需要,
可能是看看程式碼,或是寫寫Poc/Exploit
但就算需要,也不太可能要像是軟體開發那樣熟悉。

然後我們回到面試的部分~
其實還是有一些公司的資安職缺,會有程式的面試,
我自己有遇到幾個(算少數),客觀來說應該都是偏簡單的,
但因為我平常真的沒寫程式,所以面試不是很順利QQ

大部分遇到都是算選擇題或是像問答題,
像是看程式碼,選擇一個程式跑完會顯示的答案(基礎程式概念),
或是者看一段程式碼,看哪裡有漏洞,是甚麼樣的漏洞(偏資安),
也有遇到刷題的,難度大概也就leetcode Easy的程度。
只有一間有遇到比較硬的程式相關問題,
但那個職務比較特別,本來就是進去會跟資安與開發有相關的。

總之~大家如果有機會,還是可以準備一些基礎的程式設計相關知識。

照慣例,每篇文章都會附上第一篇的文章,讓大家了解一下這系列文章說明
https://ithelp.ithome.com.tw/articles/10264252

1.What will be printed in C , and why?

printf("hello\n") | (printf("goodbye\n") || printf("world\n"));

2.What is the output of the following code?

int a = 1; int b = 2; int c = 3;
switch (a) {
 case 3:
   System.out.println(b);
   break;
 default:
   System.out.println(c);
}

3.What is the output of the following code in Java, and why?

String a="cat";
String b="cat";
System.out.println(a==b);
c="cat";

System.out.println(a==c); 
System.out.println(a.equals(c)); 
System.out.println(c==b); 

4.What is the problem with the following code?

name = "Prejith"
age = 26
print ("Your name & age are ", name + age)

5.What is the problem with the following code?

a = 3
s = a + 10
a = "New"
q = a / 10

6.What vulnerabilities may exist in the following code, where is the problem, and how to fix it?

#include <stdio.h>
#include <string.h>

int main(void)
{
    char buff[15];
    int pass = 0;

    printf("\n Enter the password : \n");
    gets(buff);

    if(strcmp(buff, "thegeekstuff"))
    {
        printf ("\n Wrong Password \n");
    }
    else
    {
        printf ("\n Correct Password \n");
        pass = 1;
    }

    if(pass)
    {
       /* Now Give root or admin rights to user*/
        printf ("\n Root privileges given to the user \n");
    }

    return 0;
}

來源:
https://www.thegeekstuff.com/2013/06/buffer-overflow/

7.What vulnerabilities may exist in the following code, where is the problem, and how to fix it?

<?php
    
echo "Hello, " . $_GET['name'];

?>

8.What vulnerabilities may exist in the following code, where is the problem, and how to fix it?

$la = $_GET['lang'];
if(isset($la))
{
    include("langs/$la");
}
else
{
    include("en.php");
}

9.What vulnerabilities may exist in the following code, where is the problem, and how to fix it?

$db = new mysqli('localhost', 'root', 'passwd', 'base');
$result = $db->query('SELECT * FROM users WHERE user="'.$_GET['user'].'" AND pass= "'.$_GET['password'].'"');

來源:
https://support.detectify.com/support/solutions/articles/48001048942-sql-injection

10.What vulnerabilities may exist in the following code, where is the problem, and how to fix it?

<?php

    header("Set-Cookie: count=" . $_GET["count"] . ";");
    header("Set-Cookie: secret=" . $secret . "; HttpOnly");

    echo "Hello Guest~";

?>

11.Which line of code uses Python to display the numbers 0 through 9 in the console?

(A)for (var i=0; i < 10; i++) console.log(i);
(B)for i in range(10): print(i)
(C)for i in range(9): log(i)
(D)for i in [0-10]: print(i)
(E)for i am printing 0-9

最後一題是來自於freeCodeCamp.org這個Youtube頻道
他的社群部分常常會有這種很有趣的小問題喔!
https://www.youtube.com/c/Freecodecamp/community


如果是偏資安一點的,
可以多研究看看像是code裡面有甚麼問題,邏輯漏洞或是WEB漏洞,
如果是不是資安的話,
就是刷題吧XD 各種排序法、演算法呀,
還有Linked List,之間面試遇到,我直接空白QQ

若有要補充也都歡迎留言


上一篇
無線網路篇(Wi-Fi)
下一篇
雜七雜八問題篇
系列文
過關斬將,資安面試300題30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言