我正在试验对Linux上用C编写的程序的控制流劫持攻击.我正在尝试对启用了No-eXecutable-stack对策的程序执行简单的ret-2-libc攻击.为此,我将返回system()带参数的函数/bin/sh.
但是我遇到了一个问题:虽然我的攻击有效并且shell成功生成,但是在进入第一个角色后shell立即退出!也就是说,按下任意键后shell关闭!
在这个简单的C代码中也可以观察到这种行为:
int main() { system("/bin/sh"); return 0; }
Run Code Online (Sandbox Code Playgroud)
我用它编译它: gcc code.c -o system
为什么是这样?我该如何解决?
我在尝试Ubuntu-9.04使用kernel 2.6.28和glibc-2.9-1
更新:当且仅当我按下的第一个键时,shell才会变为交互式Enter.也就是说,如果我输入的第一个字符是a new-line(\n),那么shell将保持打开状态并变为交互式.
所以有人能解释这里发生了什么吗?
我正在用Java编写一个简单的HTTPS代理程序用于教育目的.我的程序在一个端口(比如7443)上侦听来自浏览器(比如Firefox)的传入HTTPS请求,解析请求并将其转发到所需的目的地(比如https://www.comodo.com).
Firefox的代理设置设置为使用我的端口进行SSL连接(127.0.0.1 : 7443).
我的代码简短而简单:
static // initializer
{
System.setProperty("javax.net.ssl.keyStore", "MyKeyStore");
System.setProperty("javax.net.ssl.keyStorePassword", "password");
}
SSLServerSocketFactory ssFactory = (SSLServerSocketFactory) SSLServerSocketFactory.getDefault();
try {
SSLServerSocket listener = (SSLServerSocket) ssFactory.createServerSocket(port, 64);
listener.setUseClientMode(false);
listener.setWantClientAuth(false);
listener.setNeedClientAuth(false);
SSLSocket connection = (SSLSocket) listener.accept();
browser.startHandshake(); /* <<== Exception throws at this line */
} catch (IOException ex) {
ex.printStackTrace(System.err);
}
Run Code Online (Sandbox Code Playgroud)
但是我抓住了以下异常:
javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection?
Run Code Online (Sandbox Code Playgroud)
例外情况表明连接可以是纯文本,但只有来自Firefox的HTTPS连接设置为使用此端口.我已经记录了Firefox发送到我的应用程序的内容,这是:
CONNECT www.comodo.com:443 HTTP/1.1
User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:20.0) Gecko/20100101 Firefox/20.0
Proxy-Connection: …Run Code Online (Sandbox Code Playgroud) 我正在编写一个Java程序,它给出了一个限定名(如java.lang.String:),从src.zipJDK中的文件中获取并返回相应的条目以供进一步处理.
到目前为止,我的程序适用于任何引用特定.java源文件的限定名称; 但是当限定名称引用整个包时(例如:),我遇到了麻烦java.util.*.在这种情况下,我希望我的程序返回给定包中所有条目的列表.
问题是似乎没有办法(有效地)使用java.util.zip.*包中提供的实用程序来做这样的事情!我已经尝试了两个ZipFile并且ZipInputStream没有人识别文件中的src.zip目录!他们只返回单个.java源文件的条目!
在代码语言中,两者都是:
ZipEntry entry;
ZipInputStream zip = new ZipInputStream(new FileInputStream("src.zip"));
while((entry = zip.getNextEntry()) != null)
System.out.println(entry.isDirectory());
Run Code Online (Sandbox Code Playgroud)
和:
Enumeration<? extends ZipEntry> zip = new ZipFile("src.zip").entries();
while (zip.hasMoreElements()) {
ZipEntry entry = zip.nextElement();
System.out.println(entry.isDirectory());
}
Run Code Online (Sandbox Code Playgroud)
总是回归虚假; 根本没有目录!
即使以下代码是无用的,只返回null(这意味着Not Found):
ZipFile zipfile = new ZipFile("src.zip");
zipfile.getEntry("java/util/");
Run Code Online (Sandbox Code Playgroud)
解决方法是使用上面列出的两次迭代中的任何一种,并对所需的条目执行详尽的搜索:
if (entry.getName().startsWith("java/util/"))
System.out.println(entry);
Run Code Online (Sandbox Code Playgroud)
但显然这效率不高!有没有办法检索src.zip文件中的目录条目或有效地列出给定目录路径的条目?请注意,我想直接处理ZIP文件而不提取(出于显而易见的原因).
从Timothy Truckle的回答中可以 …
我正在尝试编写Java HTTP代理隧道程序,我需要有关用于通信的最佳和最快流的专家建议.
我已经实现了基本功能,一切正常.唯一的问题是通信速度或性能.我的HTTP代理系统包括在远程服务器上运行的服务器程序和在本地计算机上运行的客户端程序.到目前为止,该程序看起来像这样:
Listener.java:
/**
* Listens and accepts connection requests from the browser
*/
ServerSocket listener = null;
try {
listener = new ServerSocket(port, 128);
} catch (IOException ex) {
ex.printStackTrace(System.err);
}
ExecutorService executor = Executors.newCachedThreadPool();
Socket connection;
while (!shutdown) {
try {
connection = listener.accept();
executor.execute(new ProxyTunnel(connection));
} catch (IOException ex) {
ex.printStackTrace(System.err);
}
}
Run Code Online (Sandbox Code Playgroud)
ProxyTunnel.java:
try {
byte[] buffer = new byte[8192]; // 8-KB buffer
InputStream browserInput = browser.getInputStream();
OutputStream browserOutput = browser.getOutputStream();
// Reading browser request …Run Code Online (Sandbox Code Playgroud) 有趣的是,对于看似常见的场景,我找不到任何解决方案!所以我在这里请求向Spring Data JPA方面经验丰富的专业人士学习。我会考虑使用Lombok来使示例代码更加简洁。
考虑一个简单的IMDB示例 Web 应用程序。我定义了两个简单的实体,如下所示:
@Data
@Entity
public class Movie {
@Id
@GeneratedValue
private long id;
private String title;
private int year;
private int rating;
}
@Data
@Entity
public class Actor {
@Id
@GeneratedValue
private long id;
private String firstName;
private String lastName;
private Date birthday;
private String gender;
}
Run Code Online (Sandbox Code Playgroud)
现在我们需要一个连接表来链接这两个实体;但这不仅仅是一个简单的连接表。除了actor和movie列之外,该表还有一些附加属性。我们不想通过ID在此处添加列来浪费存储空间,而是使用由actor和组成的复合键movie:
@Data
@Embeddable
public class MovieActorId implements Serializable {
private Actor actor;
private …Run Code Online (Sandbox Code Playgroud) 假设我们有一个 JavaSocketChannel连接到一个正在等待传入数据的服务器:
SocketChannel server = SocketChannel.open();
server.connect(new InetSocketAddress(ip, port));
Run Code Online (Sandbox Code Playgroud)
我们发送我们的请求如下:
byte[] request = "This is a request for server!".getBytes();
ByteBuffer buffer = ByteBuffer.wrap(request);
buffer.flip();
int write = 0;
while (buffer.hasRemaining())
write += server.write(buffer);
System.out.println(write);
Run Code Online (Sandbox Code Playgroud)
上面的代码返回0,这意味着它不会向通道写入任何字节!
但是,如果我删除该buffer.flip()行,它将正常工作并发送数据:
byte[] request = "This is a request for server!".getBytes();
ByteBuffer buffer = ByteBuffer.wrap(request);
int write = 0;
while (buffer.hasRemaining())
write += server.write(buffer);
System.out.println(write);
Run Code Online (Sandbox Code Playgroud)
为什么是这样 ?!