程序语言篇

学资安需要会写程序吗?

最近才看到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

若有要补充也都欢迎留言


<<:  Day27 - 子状态 or 子状态机?与外部沟通!概念简介: invoke services v.s. spawn actors in XState

>>:  Day30-结赛感言之 This is not the end

[Day 21] Leetcode 560. Subarray Sum Equals K (C++)

前言 今天这题也是来自top 100 liked的题目,题目是:560. Subarray Sum ...

Day29 procfs, sysfs, debugfs

前言 讲完了复杂了中断处理,铁人赛的倒数第二天,要来看看一些虚拟的文件系统了,首先是 procfs ...

EP25 - EKS 日志蒐集使用 Loki 和 Grafana(一)

前四天我们经历一番折腾, 终於把 Octopus Deploy 架起来, 从 Octopus Dep...

Day 12 wireframe 大城市综览 + 天气预报( side project 配对单有意者请进)

今天开了配对单给大家做 side project,有兴趣可以来找找夥伴,前後端 / UIUX 皆可~...

Day 22-制作购物车之前端架构2&Navbar设计

设计的部分就不多做分析,主要呈现实作成果。 以下内容有参考教学影片,底下有附网址。 (内容包括我的不...