byte oriented and wide oriented

本文探讨了在文件操作中如何通过调用fwide函数实现字节对齐与宽字符对齐,解释了它们在不同场景下的应用与区别,并通过代码实例演示了如何正确使用这些概念来避免读写失败。

byte oriented and wide oriented

Byte orientation refers to forms of data processing in which digital data are processed bytewise. For example, communication is called byte oriented or character oriented when the transmitted information is grouped into bytes.

The latter term is deprecated, since the notion of character has changed. An ASCII character fits to one byte (octet) in terms of the amount of information. With the internationalization of computer software, wide characters became necessary, to handle texts in different languages. In particular, Unicode characters can be 8, 16, or 32 bits long, i.e., 1, 2, or 4 bytes.

Byte oriented transmission makes use of byte-oriented protocols, that may involve transmission of additional bits as terminators, means of error recovery, etc.

Alternative approaches are bit oriented and word oriented.

—— wikipedia

上面是wiki 对byte oriented 和 wide oriented给出的解释。。。为byte oriented 和 wide oriented纠结好久

这和标准库函数函数fwide有关系:

#include <stdio.h>
#include <wchar.h>
int fwide(FILE *fp ,int mode);


Returns:

positive if stream is wide oriented,

negative if stream is byte oriented,

or 0 if stream has no orientation

The fwide function  performs  different  tasks,  depending  on  the  value  of  the mode
argument.
•If the mode argument  is  negative, fwide will  try  to  make  the  specified  stream
byte oriented.
•If the mode argument  is  positive, fwide will  try  to  make  the  specified  stream
wide oriented.
•If the mode argument  is  zero, fwide will  not  try  to  se
t  the  orientation,  but  will

still return a value identifying the stream’s orientation.

google了很多,也没给出具体是啥效果作用。。。

自己上!

Byte oriented 和 wide oriented是用来限制单次读写stream 的字节数的

如果不按照规则读写,则会发生读写失败

fwide(file_pointer,positive_number);

这样就可以把当前的file_pointer指向的流oriented 为widecharacter那么这个时候对这个流的每次读写操作都不能是以单个字节

test:

#include"stdio.h"
#include"string.h"

#defineBUFFSIZE 1024
#definePOSITIVE 1
 
intmain()
{
        FILE* file_pointer = NULL;
        char buffer[BUFFSIZE];
 
        int byte = 0;
 
        memset(buffer,0,BUFFSIZE*sizeof(char));
 
        file_pointer =fopen("./test.txt","r+");
 
        if(file_pointer == NULL)
        {
                printf("fopenerror\n");
                return 0;
        }
 
        fwide(file_pointer,POSITIVE);
 
        while((byte =fread(buffer,sizeof(char),BUFFSIZE,file_pointer)) > 0)
        {
               fwrite(buffer,sizeof(char),byte,stdout);
        }
 
        fclose(file_pointer);
        return 0;
}

root@ubuntu:/Ad_Pro_in_Unix/chapter_5#gcc ./fwide_test.c -g -o ./a.out

root@ubuntu:/Ad_Pro_in_Unix/chapter_5#./a.out

root@ubuntu:/Ad_Pro_in_Unix/chapter_5#

可以看到,这样读写就是失败的,不能用单个字节的方式读写这个流


对fwrite和fread做修改,改为每次读取多个字节

#include"stdio.h"
#include"string.h"
 
#defineBUFFSIZE 1024
#definePOSITIVE 1
 
intmain()
{
        FILE* file_pointer = NULL;
        char buffer[BUFFSIZE];
 
        int byte = 0;
 
        memset(buffer,0,BUFFSIZE*sizeof(char));
 
        file_pointer =fopen("./test.txt","r+");
 
        if(file_pointer == NULL)
        {
                printf("fopenerror\n");
                return 0;
        }
 
        fwide(file_pointer,POSITIVE);
 
        while((byte =fread(buffer,4*sizeof(char),BUFFSIZE,file_pointer)) > 0)
        {
               fwrite(buffer,4*sizeof(char),byte,stdout);
        }
 
        printf("\n");
        fclose(file_pointer);
        return 0;
}

root@ubuntu:/Ad_Pro_in_Unix/chapter_5# ./a.out

hello world!

wakaka

file standard library IO

root@ubuntu:/Ad_Pro_in_Unix/chapter_5# vim ./fwide_test.c

 

读写正常!


byte oriented的时候,stream的读写操作只能以单个字节进行,而wide oriented的时候只能以多字节形式进行。

如有理解不当的地方,还望高手明示。


### Pikachu靶场 Wide Byte SQL注入 关卡分析 Wide Byte SQL 注入是一种利用宽字符编码特性绕过过滤机制的攻击方式。在这种类型的注入中,程序可能对某些特殊字符进行了简单的过滤(如单引号 `'`),但未充分考虑多字节字符集中的转义行为。 #### 背景原理 在 Wide Byte SQL 注入场景下,目标系统的输入验证可能存在缺陷。例如,在使用 `addslashes()` 函数时,该函数会将单引号替换为 `\’`,但如果输入的是一个多字节字符序列(如 `%bf%27`),则可能导致实际解析过程中仍然存在有效的单引号[^1]。这种情况下,可以构造特定的 Payload 来实现 SQL 注入。 #### 构造Payload 对于Pikachu靶场中的Wide Byte SQL注入关卡,可以通过以下方式进行尝试: ```sql username=%bf%27 AND SLEEP(5)--+ password=1 ``` 上述Payload利用了宽字节特性以及时间延迟函数SLEEP来确认是否存在注入点。如果提交后页面响应明显变慢,则说明注入成功[^2]。 进一步获取数据库版本或其他敏感信息可采用如下形式: ```sql username=%bf%27 UNION ALL SELECT database(),version(),user()--+ password=1 ``` 此Payload通过UNION查询返回当前使用的数据库名、MySQL版本及用户身份等重要细节。 #### 自动化工具辅助检测 除了手动构造外,还可以借助Burp Suite或SQLMap这类自动化渗透测试工具完成更复杂的操作流程。以SQLMap为例,只需指定参数并附加适当选项即可快速定位潜在风险位置: ```bash sqlmap -u "http://your-pikachu-target/widebyte.php" --data="username=test&password=1" --level=5 --risk=3 --dbms=mysql ``` 以上命令设置了较高的扫描级别与风险等级,并指定了目标运行环境为MySQL实例。 ### 注意事项 尽管实验环境中允许此类活动开展学习研究工作,请务必遵循道德规范,在合法授权范围内实践技术技能提升过程。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值