杭电 Digital Roots

本文介绍了一种计算数字根的方法,即通过不断累加整数的各个位数直至得到一位数的过程。并通过一个C语言示例程序展示了如何实现这一过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


Problem Description
The digital root of a positive integer is found by summing the digits of the integer. If the resulting value is a single digit then that digit is the digital root. If the resulting value contains two or more digits, those digits are summed and the process is repeated. This is continued as long as necessary to obtain a single digit.

For example, consider the positive integer 24. Adding the 2 and the 4 yields a value of 6. Since 6 is a single digit, 6 is the digital root of 24. Now consider the positive integer 39. Adding the 3 and the 9 yields 12. Since 12 is not a single digit, the process must be repeated. Adding the 1 and the 2 yeilds 3, a single digit and also the digital root of 39.
 

Input
The input file will contain a list of positive integers, one per line. The end of the input will be indicated by an integer value of zero.
 

Output
For each integer in the input, output its digital root on a separate line of the output.
 

Sample Input
  
24 39 0
 

Sample Output
  
6 3
 

Source
 

Recommend
We have carefully selected several similar problems for you:   1017  1016  1019  1014  1010 
题意:本题要求的是给出一个整数,求该整数的各位数字之和;
分析:本题需注意的是,体重并没给出整数的位数,故需要很容易想到字符数组,然后用一循环即可解出;
代码:

#include<stdio.h>
#include<string.h>
int fun(int n)
{
 int num=0,t,s;
  while(n!=0)
    {
  t=n%10;
  num+=t;
  n=n/10;
 }
   return num;
}
int main()
{
 int m,i,j,p;
 int sum;
   int a[100000];
   char a1[100000];
 while(~scanf("%s",a1))
 {
  if(strcmp(a1,"0")==0)
  break;
  p=strlen(a1);
   for(i=0,j=p-1;j>=0;i++,j--)
    a[j]=a1[i]-'0';
    for(i=0,sum=0;i<p;i++)
    sum+=a[i];
     while(1)
     {
      m=fun(sum);
      if(m<10)
      break;
      sum=m;
     }
 
     printf("%d\n",m);
 }
 return 0;
}



在CTF(夺旗赛)竞赛中,获取Root权限或完成Root级别挑战通常涉及对系统漏洞的深入理解和利用。这类挑战通常要求参赛者通过各种技术手段提升自身的权限至最高级别(如Linux系统中的root用户),以便访问受限资源或获取隐藏信息。 ### Root级别挑战的常见类型 1. **本地提权(Local Privilege Escalation, LPE)** 本地提权是CTF中常见的Root级别挑战之一,通常涉及利用目标系统上存在的配置错误、内核漏洞或服务缺陷来提升当前用户的权限。例如,某些SUID二进制文件可能包含缓冲区溢出漏洞[^1],或者存在可被劫持的环境变量调用路径。攻击者可以通过构造特定输入来执行任意代码并获取高权限。 2. **内核漏洞利用(Kernel Exploitation)** 这类挑战通常要求选手理解Linux内核机制,并能够识别和利用内核模块中的漏洞,如UAF(Use-After-Free)、整数溢出、竞态条件等。这些漏洞一旦被成功利用,往往可以直接获得root权限。 3. **容器逃逸(Container Escape)** 在现代CTF比赛中,有时会设置基于Docker或其他容器技术的题目。攻击者需要找到方法从容器内部逃逸到宿主机环境中,并进一步获取root权限。这通常涉及对cgroups、命名空间或挂载点配置的误解。 4. **物理内存访问与DMA攻击模拟** 某些高级题目可能会模拟通过PCIe设备或FireWire接口进行直接内存访问(DMA)的场景。这种攻击方式可以绕过常规的安全机制,从而实现提权。 5. **服务提权(Service-Based Privilege Escalation)** 一些系统服务(如cron、systemd、sudoers等)的不当配置也可能成为提权途径。例如,sudoers文件中未正确限制的命令可能导致攻击者以root身份运行任意程序。 ### 常见Root提权技术示例 #### 利用SUID二进制文件 某些具有SUID位设置的程序会在执行时以文件所有者的权限运行。如果该程序存在漏洞(如`/usr/local/bin/vuln_binary`),攻击者可以尝试利用缓冲区溢出或命令注入等方式执行任意代码: ```bash find / -user root -perm -u+s 2>/dev/null ``` 上述命令可用于查找系统中所有具有SUID权限的文件,进而分析是否存在可利用的程序[^1]。 #### 利用定时任务(Cron Jobs) 检查是否有以root权限运行的定时任务,并查看其脚本是否允许低权限用户修改: ```bash cat /etc/crontab ls -l /etc/cron.d/ ``` 若发现某个脚本由root运行且可被当前用户写入,则可通过修改该脚本内容实现提权。 #### 内核模块加载提权 某些情况下,攻击者可以加载恶意内核模块(LKM)来修改系统行为,例如隐藏进程、篡改系统调用表等。此类攻击通常需要关闭SELinux或AppArmor等强制访问控制机制。 ### Root级别挑战的准备建议 - **学习Linux系统安全机制**:包括但不限于ASLR、NX、PIE、Canary、Seccomp等。 - **掌握基础漏洞利用技巧**:如栈溢出、堆喷射、ROP链构造等。 - **熟悉调试工具**:GDB、pwntools、radare2等用于逆向分析与漏洞挖掘。 - **研究公开的Exploit案例**:如CVE-2021-4034(Pwnkit)、CVE-2022-0847(Dirty Pipe)等知名提权漏洞。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值